Я хочу построить график для сравнения случаев каждой страны, где я вводил по строке. Я импортирую данные из здесь
Вот пример того, что я ожидаю:
Из этого пи c. Я ввожу N = 3 для диапазона стран для ввода. И я ввожу название каждой страны шаг за шагом. Отныне. Если я хочу построить график, по каким странам я был введен для сравнения количества случаев на одном графике, как я могу это сделать?
Вот мой код:
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#read file
dfi = pd.read_csv('time_series_covid19_confirmed_global.csv', sep=',')
df = dfi.drop(['Province/State','Lat','Long'], axis=1)
df
#sum all the cases of each province/State to 1 row.
df_gr = df.groupby('Country/Region').sum()
time = df_gr.columns.tolist()
df_gr.columns = pd.to_datetime(time)
df_gr.reset_index(inplace = True)
countriesx = df_gr['Country/Region'].unique() #keep each country into list.
countries_list = [x for x in countriesx] #clean the data.
df = df_gr.T
new_header = df.iloc[0]
df = df[1:]
df.columns = new_header
#input the number of countries to compare.
while True:
N = int(input('The number of countries to compare: '))
if N < 1 or N > 185:
print('The value must between1 and 185. Try again.\n')
continue
else:
print('Correct inout.\n')
break
#input name of countries to compare.
cnt = len(countries_list)
choose = [] #For the name of each countries.
for i in range(N):
print(f'Country {i+1} of {N}')
while True:
my_countries = input('Enter the full country name: ')
my_countries = my_countries.capitalize()
countries_list.append(my_countries)
set_checker = set(countries_list)
if len(set_checker) == cnt:
print(f'Country {i+1} confirmed as \'{my_countries}\'.\n')
choose.append(my_countries)
break
else:
print(f'There is no country named \'{my_countries}\'. Try again\n')
countries_list.remove(my_countries)
continue
Это то, что я пытался .