Plotting two dataframes into one bar chart, distinguish their values

I am confusing myself with the following task and I hope someone can point me to the right direction. I have two datasets, one with data from January 2019 and another one with data from January 2020.

df1

ID     Date
5177   2019-01-31
5178   2019-01-31
5179   2019-01-31
5180   2019-01-31
5181   2019-01-31
5182   2019-01-31
5183   2019-01-31
5184   2019-01-30
5185   2019-01-30
5186   2019-01-30

df2

ID     Date
2918   2020-01-31
2919   2020-01-31
2920   2020-01-31
2921   2020-01-31
2922   2020-01-31
2923   2020-01-31
2924   2020-01-31
2925   2020-01-31
2926   2020-01-30
2927   2020-01-30

I tried to plot them as line charts as follows:

df1.groupby('Date').size().plot()
df2.groupby('Date').size().plot()

plt.xticks(rotation=90)
plt.show() 

but the output is not good as the results as shown in two different areas of the chart (one is 2019 and another one is 2020). So what I have been trying to do is to plot these data as bar charts, putting bars close to each other I order to easily compare the frequency of data day by day through months.

I have tried as follows:

df1.groupby(['Date'])['Date'].size().plot(kind='bar')
df2.groupby(['Date'])['Date'].size().plot(kind='bar')

but this does not distinguish between values from df1 and values from df2 (also, bars are in the same colour).

What I would like to have is a chart with on the x-axis the date (only days, as months are the same and I know which year I am comparing). With different colour, I would need to plot data from 1 and data from 2 (the legend will tell which df1/2 is).

Can you please tell me how to plot data to get the expected output?

Thanks



from Recent Questions - Stack Overflow https://ift.tt/34J5wQo
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation