Issue
I have the dataset shown below. I am trying to sort it so that the columns are in this order: Week End, Australia, Germany, France, etc...
I have tried using loc
and assigning each of the data sets as variables but when I create a new DataFrame it causes an error. Any help would be appreciated.
This is the data before any changes:
Region | Week End | Value |
---|---|---|
Australia | 2014-01-11 | 1.480510 |
Germany | 2014-01-11 | 1.481258 |
France | 2014-01-11 | 0.986507 |
United Kingdom | 2014-01-11 | 1.973014 |
Italy | 2014-01-11 | 0.740629 |
This is my desired output:
Week End | Australia | Germany | France | United Kingdom | Italy |
---|---|---|---|---|---|
2014-01-11 | 1.480510 | 1.481258 | 0.986507 | 1.973014 | 0.740629 |
What I've tried:
cols = (['Region','Week End','Value'])
df = GS.loc[GS['Brand'].isin(rows)]
df = df[cols]
AUS = df.loc[df['Region'] == 'Australia']
JPN = df.loc[df['Region'] == 'Japan']
US = df.loc[df['Region'] == 'United States of America']
Solution
I think that you could actually just do:
df.pivot(index="Week End", columns="Region", values="Value")
Answered By - 965311532
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.