[英]python read excel data, filling missing values using pandas
table 1: first table 表1:第一个表 table 2: second table in single sheet. 表2:单张纸中的第二个表。
guys i want to read and fill missing values of excel data . 伙计们,我想读取并填充Excel数据的缺失值。 but i have many table in single sheet, how can i split it and only fill table data values of different tables. 但是我在一张纸上有很多表格,我该如何拆分它并只填充不同表格的表格数据值。
here's my code: 这是我的代码:
#read excel files
import pandas as pd
import numpy as np
stations_data = pd.read_excel('filename', sheet_name=0, skiprows=6)
#get a data frame with selected columns
FORMAT = ['S.No.', 'YEAR', 'JUNE']
df_selected = stations_data[FORMAT]
for col in FORMAT:
for idx, rows in df_selected.iterrows():
if pd.isnull(df_selected.loc[idx,col]):
df_selected = df_selected.fillna(df_selected.mean())
print (df_selected)
You could use pd.read_excel
where you use the key word argument skiprows
to start at the 'correct' row for the specific table and skipfooter
to stop at the correct row. 您可以使用pd.read_excel
,其中使用关键字参数skiprows
在特定表的“正确”行开始,而skipfooter
在正确的行停止。 Of course this may not be so practical if the number of rows in the tables change in the future. 当然,如果将来表中的行数发生变化,这可能不太实用。 Maybe it is easier to just restructure the excel to have one table per sheet, and then just use the sheetname
kwarg. 也许是容易只是重组的Excel中有每张一个表,然后只需使用sheetname
kwarg。 See the documentation . 请参阅文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.