Apologies if something similar has been asked before, I searched around but couldn't figure out a solution.
My dataset looks like such
data1 = {'Group':['Winner','Winner','Winner','Winner','Loser','Loser'],
'Study': ['Read','Read','Notes','Cheat','Read','Read'],
'Score': [1,.90,.80,.70,1,.90]}
df1 = pd.DataFrame(data=data1)
This dataframe spans for dozens of rows, and have a set of numeric columns, and a set of string columns. I would like to condense this into 1 row, where each entry is just the mean or mode of the column. If the column is numeric, take the mean, otherwise, take the mode. In my actual use case, the order of numeric and object columns are random, so I hope to use an iterative loop that checks for each column which action to take.
I tried this but it didn't work, it seems to be taking the entire Series as the mode.
for i in df1:
if df1[i].dtype == 'float64':
df1[i] = df1[i].mean()
Any help is appreciated, thank you!
