[英]How can I read specific data in my exel sheet and create a plot from each dataset that is read? (Python)
Here is the code that I have so far:这是我到目前为止的代码:
import numpy as np
import pandas as pd
import csv
file = r'C:\Users\Tiago Costa\Desktop\Senior Year - 2019.2020\ME 130\Coronovirus Datasets\time_series_2019-ncov-Confirmed.xlsx'
data = pd.ExcelFile(file)
print(data.sheet_names)
['Worksheet']
df = data.parse('Worksheet')
df.info
df.head(483)
I was wondering how I would be able to only extract the number of confirmed cases for China, Italy, Germany, Iran and USA, and then plot that data as a function of time.我想知道如何才能仅提取中国、意大利、德国、伊朗和美国的确诊病例数,然后将这些数据绘制为时间的函数。
I was going to be using this: https://pythonprogramming.net/loading-file-data-matplotlib-tutorial/ as a reference to create my plots when I got to that point.我打算使用这个: https : //pythonprogramming.net/loading-file-data-matplotlib-tutorial/作为参考,当我到达那个点时创建我的图。
Thank you!谢谢!
You don't need to convert it into .xlsx
file first, because we can use .read_csv()
.您不需要先将其转换为
.xlsx
文件,因为我们可以使用.read_csv()
。 Then you can use .isin()
to filter which countries you want to take.然后你可以使用
.isin()
来过滤你想要去的国家。
data = pd.read_csv('time_series_2019-ncov-Confirmed.csv')
countries = ['China', 'Italy', 'Germany', 'Iran', 'USA']
filtered_data = data[data['Country/Region'].isin(countries)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.