Reputation: 3667
pivot_table
is dropping columns that are NOT being pivoted.
I have a df that looks like this:
id FieldTitle Value number
1 fname aaa 12
2 lname bbb 12
When I run this line of code:
pivoted_df = pd.pivot_table(df, index='Id', columns='FieldTitle', values='Value', aggfunc='first').reset_index()
The df that is left is:
fname lname
aaa bbb
Why is pivot causing the other columns to disappear and how do I fix it?
The df should look like this:
id fname lname number
1 aaa bbb 12
Upvotes: 1
Views: 3019
Reputation: 249223
I guess you want:
values=['Value', 'number']
Or if you want all possible columns, don't pass values
at all.
Upvotes: 2