I have the following Pandas dataframe:
import pandas
df = pandas.DataFrame({'Status': ['Draft',
'Active','Completed','Completed', 'Draft', 'Active'], 'Region':
['Europe','Europe', 'Asia','Australia', 'Asia', 'Australia'],'Budget': [1000,
2000,3000,4000,5000,6000]})
I am grouping and aggregating it as follows:
grouped_by_region = df.groupby('Region').agg({'Budget':sum})
So the output of print(grouped_by_region)
is:
Region Budget
Asia 8000
Australia 10000
Europe 3000
What I want to do is split the budget column into "Budget draft", "Budget active", "Budget completed" columns. So basically I need to create new columns based 'Status' column values and rename them accordingly.
How to achieve this?