'How to group by and plot sales data after grouping by month and year, and sales amount for each part in python?
Below is my current code. I can get everything to run, except for the plot. Any suggestions would be greatly appreciated. The data being used is sales data over the coarse of 5 years. Column headings are:
Column Dtype
0 internal_fl object
1 invoicedate object
2 refkey3 object
3 refkey_desc object
4 ordernbr int64
5 orderlinenbr int64
6 ecwebordnbr object
7 ordertype object
8 order_source_group object
9 order_source_desc object
10 claim_no float64
11 resp object
12 cl_type object
13 credit_type object
14 acmodel object
15 acserial object
16 customer int64
17 cust_type_desc object
18 cust_type_group object
19 qty int64
20 salesamount_usd float64
21 item object
22 non_item float64
23 listprice float64
24 custprice float64
25 addl_disc_fl object
26 unitprice float64
27 disccode object
28 pricelist object
29 pct float64
30 alphacode object
31 purchmajcl object
32 policycode object
import pandas as pd
import csv
import os
df = pd.read_csv (r'/Users/me/Desktop/Part Sales.csv')
df_2 = pd.read_csv (r'/Users/me/Desktop/Part Sales2.csv')
concatenated = pd.concat([df, df_2]).drop_duplicates().reset_index(drop=True)
concatenated.head(10)
import matplotlib.pyplot as plt
import seaborn as sns
concatenated.shape
concatenated.columns
concatenated.info()
concatenated.isnull().sum()
concatenated.describe()
concatenated['invoicedate'].min()
concatenated['invoicedate'].max()
concatenated['month_year'] = concatenated['invoicedate'].apply(lambda x: '/'.join(x.split('/')[0:2]))
concatenated['month_year']
concatenated_trend = concatenated.groupby(['month_year'])['salesamount_usd'].sum() #reset_index()
concatenated_trend
plt.figure(figsize=(15,6))
plt.plot(concatenated_trend['month_year'], concatenated_trend['salesamount_usd'])
plt.xticks(rotation='vertical', size=8)
plt.show()
This is the error message displayed: Error message
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
