I am looking for an efficient way to transform a dataframe... I have a dataframe of the form where: pandas dataframe
I would like to transpose the columns and transform that into a dataframe of the form (I dont care about column names): enter image description here
Thank you!
I dont know if this is efficient but I tried getting the names I was interested in, in this way:
def players_names(df,col,names):
new_df=df.loc[df[col].isin(names)].reset_index(drop=True)
e_names=new_df[col].unique().tolist()
return e_names
And then transform the columns into arrays and transpose them like this (a loop is missing):
def players_points(df,col,name):
filt=(df[col]==name)
new_df=df[filt].reset_index(drop=True).drop(col,axis=1).T
pts=new_df.iloc[:,0:].values.tolist()
return pts