python - With for loop, run a model across multiple pandas columns and create new columns with model output -
for 4 columns in dataframe, i'd run model on each of these , append results 4 new columns original dataframe.
i have below:
materials = ['var1', 'var2', 'var3', 'var4'] materials_new= ['found_new', 'walls_new', 'roof_new', 'floor_new'] i, j in zip(materials, materials_new): df["%s"]=mlb.inverse_transform(grid_search_rf.predict(df[i])) % j
however produced error, "typeerror: unsupported operand type(s) %: 'list' , 'str'".
any advice on how create new dataframe column names loop , list, great.
side note: i'm able run model individually on 4 columns create new columns in df, don't believe error related model. @ point i'll repeating exercise 12+ columns, i'm trying pursue loop method.
thanks!
try this:
for i, j in zip(materials, materials_new): df[j]=mlb.inverse_transform(grid_search_rf.predict(df[i]))
Comments
Post a Comment