I am trying to convert a single column into row and get get corresponding values of that row into its columns.
I tried using pivot table but it gives me the nulls for all other columns where there is no specific corresponding values, but it don't want NaN in the data frame.
I have below data frame df:
week value
1 1234
1 5678
1 9856
1 5486
1 4569
2 1234
2 5869
2 4865
2 5589
I tried
df1 = df.pivot(columns='week',values='value')
This code returns the data frame with NaN, I want to eliminate all the NaN and get values of each week.the result is shown below. I have added both expected output and the actual output.
The expected result is:
1 2
1234 1234
5678 5869
9856 4865
5486 5589
4569 NaN
The actual result is
1 2
1234 NaN
5678 NaN
9856 NaN
5486 NaN
4569 1234
NaN 5869
NaN 4865
NaN 5589
I want to remove NaN and align values which belongs to that particular week.