So, I am learning pandas and I have this problem.
Suppose I have a Dataframe:
ABC 1 x NaN 2 y NaN 3 x NaN 4 x NaN 5 y NaN
I am trying to create this:
ABC 1 x [1,3,4] 2 y [2,5] 3 x [1,3,4] 4 x [1,3,4] 5 y [2,5]
Based on B.'s similarities
I have done this:
teste = df.groupby(['B']) for name,group in teste: df.loc[df['B'] == name[0],'C'] = group['A'].tolist()
And I realized that. Like column C based on column A.
ABC 1 x 1 2 y 2 3 x 3 4 x 4 5 y 5
Can someone explain to me why this is happening and the decision to do it the way I want? Thanks:)
source share