Question:
I want to reorganize some data in a Pandas DataFrame from an existing DataFrame such that I can have a subset of row values (in the minimal example below ‘City’ as columns, and remove rows not having either of the chosen values, below ‘New York’ and ‘Amsterdam’).To illustrate what I mean by the above, I have a DataFrame that looks like this:
Here is my code so far:
Answer:
As order is important we first need to create a categorical column based on City.Then we can create a pivot using
pd.pivot_table
If you have better answer, please add a comment about this, thank you!