python - ValueError In Pandas -
i have data frame 15 columns suppose out of want 6. performing aggregate , group throwing error.
def my_compute_function(my_input): df = pd.dataframe(my_input) df2 = df[(df['d'] == "validated")] df2[['a','e','f']] = df2[['a','e','f']].apply(pd.to_numeric) df3=df2[['a','b','c','d','e','f']].groupby(['b','c','d']).agg({'a': 'max','e': 'max','f': 'max'}).reset_index() return df3
so want 6 columns a,b,c,d,e,f.
when adding line
df2[['a','e','f']]=df2[['a','e','f']].apply(pd.to_numeric)
it throwing error valueerror: can not infer schema empty dataset
.
for me working perfectly, .copy
necessary:
df = pd.dataframe({ 'd':['validated','validated','a'], 'e':['4','8','8'], 'a':['4','5','8'], 'f':['4','9','8'], 'b':['a','a','r'], 'c':['b','b','b']}) df2=df[(df['d'] == "validated")].copy() print (df2) b c d e f 0 4 b validated 4 4 1 5 b validated 8 9 #for replace ',' '.' df2[['a','e','f']]=df2[['a','e','f']].replace(',','.', regex=true).apply(pd.to_numeric) df3=df2.groupby(['b','c','d']).agg({'a':'max','e': 'max','f': 'max'}).reset_index() print (df3) b c d f e 0 b validated 5 9 8
Comments
Post a Comment