'How to plot dates on a monthly/weekly basis in pandas dataframe
I have following dataframe:
Date Embedded_text Partei sentiment_prediction Sentiment
Date
2021-03-26 2021-03-26 AfD wirkt.\n\nSchluss mit dem #Gendergaga\nMDR... AfD 2 Neutral
2021-03-27 2021-03-27 Im Herbst wird gewählt.\nSchluss mit den Recht... AfD 1 Negative
2021-03-31 2021-03-31 Behördenwillkür\nFlüchtlingsheime durchgedrück... AfD 1 Negative
2021-04-01 2021-04-01 Aus Raider wird jetzt Twix \n\nLeider kein #Ap... AfD 2 Neutral
2021-04-01 2021-04-01 Gendern geht („*innen“)\nImpfen geht nicht.\nD... AfD 1 Negative
... ... ... ... ... ...
The time range of the dataframe goes from 01.01.2021 until 01.01.2022. Now I want to plot different things over time, for example:
- Plot "sentiment_prediction" over time
- Plot "sentiment_prediction" over time, grouped by "Partei"
- Plot above over all months of the year or over specific weeks
I have selected already "Date" as index. When trying to plot over the whole year, I get following output:
df["sentiment_prediction"].plot()
As you see, the plot is full of data points, because every single day is considered in this plot. That is why I want to only plot months or weeks in order to get a more insightful plot. At the moment, I don't know how to solve this.
Thanks in advance!
Solution 1:[1]
You can try to use a different time format (like MM-DD-YYYY) in the X-axis or just obtain the mean or median by every month to plot a single point.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ENCS16 |

