Convert table in pandas - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Convert table in pandas (/thread-32182.html) |
Convert table in pandas - tgottsc1 - Jan-26-2021 Hi guys, I have a very basic question about how to convert the design of a table. I would highly appreciate if someone could please help me. I have created the following table as a pandas dataframe: I would like to bring this table into the following format: I know how to run basic merge commands etc., but I have no idea how to approach this problem.Thank you so much for any help! Best, Tim RE: Convert table in pandas - buran - Jan-26-2021 DataFrame.pivot() print(df) print(df.pivot(index='element', columns='periodDescription', values='value') you can also look at pandas.pivot_table() and DataFrame.pivot_table()
RE: Convert table in pandas - tgottsc1 - Jan-26-2021 Many thanks buran, that's very helpful to know! Best, Tim |