Issue
Dataset sample for the monthly sales and semesterly sales
My data set :
Monthly_Sales
Date
28-02-2010 1057405
31-03-2010 1010665
30-04-2010 1028499
31-05-2010 1037282
30-06-2010 1068034
31-07-2010 1033689
31-08-2010 1042445
30-09-2010 984821
31-10-2010 965163
30-11-2010 1126963
31-12-2010 1283380
31-01-2011 909466
28-02-2011 1035174
31-03-2011 996424
30-04-2011 1006784
31-05-2011 1009156
30-06-2011 1054296
31-07-2011 1021828
31-08-2011 1047774
30-09-2011 981545
31-10-2011 1018118
30-11-2011 1167568
31-12-2011 1280347
31-01-2012 938302
29-02-2012 1067019
31-03-2012 1028931
30-04-2012 1049560
31-05-2012 1048702
30-06-2012 1069379
31-07-2012 1041719
31-08-2012 1052670
30-09-2012 1003586
31-10-2012 1024231
and 2nd:
Semesterly_Sales
Date
28-02-2010 1057405
31-08-2010 1036332
28-02-2011 1056477
31-08-2011 1022064
29-02-2012 1079750
31-08-2012 1048697
28-02-2013 1013908
Solution
With the graph function of pandas, you can easily stack different time periods.
import pandas as pd
import numpy as np
import io
data = '''
Date Monthly_Sales
28-02-2010 1057405
31-03-2010 1010665
30-04-2010 1028499
31-05-2010 1037282
30-06-2010 1068034
31-07-2010 1033689
31-08-2010 1042445
30-09-2010 984821
31-10-2010 965163
30-11-2010 1126963
31-12-2010 1283380
31-01-2011 909466
28-02-2011 1035174
31-03-2011 996424
30-04-2011 1006784
31-05-2011 1009156
30-06-2011 1054296
31-07-2011 1021828
31-08-2011 1047774
30-09-2011 981545
31-10-2011 1018118
30-11-2011 1167568
31-12-2011 1280347
31-01-2012 938302
29-02-2012 1067019
31-03-2012 1028931
30-04-2012 1049560
31-05-2012 1048702
30-06-2012 1069379
31-07-2012 1041719
31-08-2012 1052670
30-09-2012 1003586
31-10-2012 1024231
'''
df = pd.read_csv(io.StringIO(data), delim_whitespace=True)
df['Date'] = pd.to_datetime(df['Date'], format='%d-%m-%Y')
df.set_index('Date', inplace=True)
data2 = '''
Date Semesterly_Sales
28-02-2010 1057405
31-08-2010 1036332
28-02-2011 1056477
31-08-2011 1022064
29-02-2012 1079750
31-08-2012 1048697
28-02-2013 1013908
'''
df2 = pd.read_csv(io.StringIO(data2), delim_whitespace=True)
df2['Date'] = pd.to_datetime(df2['Date'], format='%d-%m-%Y')
df2.set_index('Date', inplace=True)
ax = df.plot(kind='line')
df2.plot(kind='line', ax=ax)
Answered By - r-beginners
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.