I am trying to create a bar chart that answers the question: Which gender spent the most money each year? I have a dataset that has each transaction listed with money spent, gender (male, female, other), and date (10-16-2014, 9-8-2015, 7-29-2016, etc.) attached to each entry. I want create a bar stacked bar chart that shows the total amount spent by each gender, every year (just the year). Please Help!
<code> THIS IS WHAT I HAVE SO FAR (Doesn't work):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style = "white", color_codes=True)
sales = pd.read_csv("/kaggle/input/mobile-sales-dataset/mobile_sales.csv")
sales.groupby(['CustomerGender'])['TotalRevenue'].sum()
genders =["Male","Female","Other"]
w = 0.2
xp = range(len(genders))
plt.bar(xp,genders)
#p1 = plt.bar(bar1, male, w, label = "Male")
#p2 = plt.bar(bar2, female, w, label = "Female")
#p3 = plt.bar(bar3, other, w, label = "Other")
plt.ylabel('Total Revenue')
plt.title('Total Revenue by Gender')
plt.xticks(xp,x)
plt.legend()
plt.show()
```
</code>
<code> THIS IS WHAT I HAVE SO FAR (Doesn't work):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style = "white", color_codes=True)
sales = pd.read_csv("/kaggle/input/mobile-sales-dataset/mobile_sales.csv")
sales.groupby(['CustomerGender'])['TotalRevenue'].sum()
genders =["Male","Female","Other"]
w = 0.2
xp = range(len(genders))
plt.bar(xp,genders)
#p1 = plt.bar(bar1, male, w, label = "Male")
#p2 = plt.bar(bar2, female, w, label = "Female")
#p3 = plt.bar(bar3, other, w, label = "Other")
plt.ylabel('Total Revenue')
plt.title('Total Revenue by Gender')
plt.xticks(xp,x)
plt.legend()
plt.show()
```
</code>
THIS IS WHAT I HAVE SO FAR (Doesn't work):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style = "white", color_codes=True)
sales = pd.read_csv("/kaggle/input/mobile-sales-dataset/mobile_sales.csv")
sales.groupby(['CustomerGender'])['TotalRevenue'].sum()
genders =["Male","Female","Other"]
w = 0.2
xp = range(len(genders))
plt.bar(xp,genders)
#p1 = plt.bar(bar1, male, w, label = "Male")
#p2 = plt.bar(bar2, female, w, label = "Female")
#p3 = plt.bar(bar3, other, w, label = "Other")
plt.ylabel('Total Revenue')
plt.title('Total Revenue by Gender')
plt.xticks(xp,x)
plt.legend()
plt.show()
```
New contributor
Collin Sewell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.