简体   繁体   English

如何读取我的 exel 表中的特定数据并从读取的每个数据集创建一个图? (Python)

[英]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.

相关问题 如何从 Python 中的 excel 工作表的每个选项卡中读取多个表格? - How to read multiple tables from each tab of an excel sheet in Python? 如何使用Python从文本文件读取unicode并将相应的字符串写入exel文件 - How to read unicode from text file and write respective string into exel file by using Python 如何从python中的特定行读取? - How can I read from specific lines in python? 我如何从 python 中的特定行读取文本文件? - How i can Read text file from a specific line in python? 如何使用 python 从列表中读取数据并将特定值索引到 Elasticsearch? - How can I read data from a list and index specific values into Elasticsearch, using python? Python:如何读取 csv 并在循环中清理我的数据 - Python: How can I read csv and clean my data in a loop 如何使用 OOP 在 Python3 中创建 Class 以从 Excel 文件加载和读取数据? - How can I create a Class in Python3 using OOP to load and read data from an Excel file? 我如何从 python 中的文本文件中读取我的数据集并在其上应用矩阵 - how I read from text file in python my dataset and applying the matrix on it 如何在python中将相同的数据从Excel工作表读取到文本文件 - How to read the same data from excel sheet to the textfile in Python 如何调整我的情节以使其更易于阅读? - How can I adjust my plot to make it easier to read?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM