Issue
Year
values to become columns & the rest of the columns to become rows. Any ideas?
the data:
Year Propertyval Cumulative
0 1 1224000.00 24000.00
1 2 1248480.00 48480.00
2 3 1273449.60 73449.60
Desired format:
Desc 1 2 3
0 Propertyval 1248480.00 1273449.60 1273449.60
1 Cumulative 24000.00 48480.00 73449.60
Solution
Does this work for you?
import pandas as pd
df = pd.read_clipboard()
df_new = df.pivot_table(columns="Year", values=["Propertyval", "Cumulative"])
Update: If you also want to reset the index and change the column name, then this would be more accurate:
import pandas as pd
df = pd.read_clipboard()
df_new = df.pivot_table(columns="Year", values=["Propertyval", "Cumulative"]).reset_index().rename(columns={'index':'Desc'}).rename_axis(None, axis=1)
Thanks for the hint @Tobias P. G.
Answered By - intedgar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.