0

I need to create a simple line chart showing the number of infected people per day in the US. The CSV file I'm using contains 212 countries in 212 different columns, but the line chart must show only infected people in the US and the date. I managed to print the graph accordingly, but for some reason it does not have the timeline in the x axis, and I was wondering how I could replace the numbers with the dates. I'm attaching a screenshot of my graph as well.

Line chartt

Here is the code for the graph:

dataframe = pd.read_csv('total_cases.modified2.csv')
plt.figure(figsize=(10,6))
plt.title('Covid19')
plt.xlabel('date')
plt.ylabel('Number of infected people')
plt.plot(dataframe['United States'], color='green')
plt.show()

This is how the CSV columns look like

Thank you!

Hahof
  • 3
  • 2
  • Does this answer your question? [plot x-axis as date in matplotlib](https://stackoverflow.com/questions/49418248/plot-x-axis-as-date-in-matplotlib) – Sam Mason Jun 05 '20 at 17:11
  • note that without some idea of your data (e.g. do you have a date column in the data? is it daily data from a known date? etc) it's difficult to suggest much. editing the question to include details would help, but there are many questions similar to this if you google for "matplotlib date x-axis" – Sam Mason Jun 05 '20 at 17:14
  • @SamMason thanks for your response. I have edited my post and included a screnshot of the csv file. The CSV file does have a column 'date', and its format is dd/mm/yyyy. I have already tried to follow some posts and I could not do it :( – Hahof Jun 05 '20 at 17:42
  • what have you tried? there are lots of options including passing `parse_dates` to `read_csv` and using `pd.to_datetime` directly. note that posting images of textual data (as CSV is) is discouraged, just paste the subset into a code block. images are difficult for people who use screen readers (e.g. the blind) – Sam Mason Jun 05 '20 at 17:49

0 Answers0