I'm trying to use the next function, but appears ValueError: Cannot set a DataFrame with multiple columns to the single column.
I used this function with others columns (CO01NUM022AH and CO01NUM022CT), and I had no problem (New columns R2 ... y R ... were created). But with the other columns (CO01EXP001VE and CO01EXP001RO) only I get columns R2 ...
Any help or suggestion would be appreciated.
That's my code. I get the error for the line number 19:
VarMeses = ('CO01EXP001VE', 'CO01EXP001RO')def RangDef0 (row): if row[column] == 0: rango = 'y. Sin antiguedad' elif row[column] > 0: rango = baseburo[NombrecolM] elif (row[column] == -1) | (row[column] == -2) | (row[column] == -3): rango = 'z. Sin informacion' else: rango = 'y. Sin antiguedad' return rangobinsM = [1, 12, 24, 48, 72, 96, 120, 144, 168, 99999]labM = ['a. 1-12 m','b. 13-24 m','c. 25-48 m','d. 49-72 m','e. 73-96 m','f. 97-120 m','g. 121-144 m','h. 145-168 m','i. >168 m']for column in VarMeses: NombrecolM = 'R2'+ str(column) NombrecolM2 = 'R'+ str(column) baseburo[NombrecolM] = pd.cut(baseburo[column], bins = binsM, labels = labM, include_lowest = True) baseburo[NombrecolM2] = baseburo.apply(RangDef0, axis=1)
This is the dataframe:
Item CO01NUM022AH CO01NUM022CT CO01EXP001VE CO01EXP001RO R2CO01NUM022AH RCO01NUM022AH R2CO01NUM022CT RCO01NUM022CT R2CO01EXP001VE R2CO01EXP001RO710059 0.0 0.0 206.0 239.0 b. 1 a. 0 b. 1 a. 0 i. >168 m i. >168 m710532 0.0 -1.0 -1.0 97.0 b. 1 a. 0 NaN z. Sin informacion NaN f. 97-120 m710895 0.0 -1.0 13.0 117.0 b. 1 a. 0 NaN z. Sin informacion b. 13-24 m f. 97-120 m711302 0.0 -1.0 -1.0 54.0 b. 1 a. 0 NaN z. Sin informacion NaN d. 49-72 m711361 0.0 -1.0 -1.0 225.0 b. 1 a. 0 NaN z. Sin informacion NaN i. >168 m