after searching, don't think duplicate, if please let me know.
i have data frame number of rows , variables. create separate data frame of single row mean of each variable. i'm doing can plot in graph. i'm not sure why syntax doesn't work.
this 1 specific variable. if can work, can expand columns loop.
avg = pd.dataframe(columns=original.columns.values) avg['max_yds'].loc[0] = original['max_yds'].mean(axis=0) in mind, first line creates data frame called 'avg' empty , has columns original. seems work expected. second line, expect set first row of variable 'max_yds' in 'avg' , set mean of variable of 'max_yds' original. instead, get: empty dataframe
thanks!
try
avg.set_value(0, 'max_yds', original['max_yds'].mean(axis=0)) if want compute mean columns, why not use
avg = avg.append(original.mean(axis=0), ignore_index=true) edit:
the problem of original solution using kind of "chained indexing", bad.
you add value series in each column, index of dataframe still empty.
actually, if add
avg['max_yds'] = avg['max_yds'] after
avg['max_yds'].loc[0] = original['max_yds'].mean(axis=0) , code work well.
or can specify index @ beginning, can fix problem.
avg = pd.dataframe(columns=original.columns.values, index=[0]) however, not recommended so.
Comments
Post a Comment