我正在读取一个excel,我想在nan值后开始几行:
NaN
NaN
NaN
NaN
Code
我正在这样做:
for data in range(len(df)):
try:
if 'Code' in df.iloc[data,0]:
df = df.iloc[data:,:]
except:
passs
但是以这种方式我错过了其他解析错误
我正在尝试:
if pd.isna(df.iloc[data,0]):
pass
if 'Code' in str(df.iloc[data,0]):
df = df.iloc[data:,:]
但是我得到:
argument of type 'float' is not iterable in the 'Code' line
任何帮助解决这个问题的方法
[我没有使用pandas
的丰富经验,但是当我阅读了read_excel的文档时,得到的内容可能会帮助您跳过NaN
值。
您可以在阅读excel时通过以下参数
您可以获得更多信息here
Skiprows将有助于从Excel中读取时跳过一些行并读取数据。
df_can = pd.read_excel('https://....Canada.xlsx',
sheet_name='Canada by Citizenship',
skiprows=range(20),
skipfooter=2)
跳过某些行后,请检查此要点,以了解如何将Excel文件读入pandas数据框中。
https://gist.github.com/dhamayanthim80/b0d861d7cffe48094f89fd8e05609e17
对不起,如果我的回答与您的问题无关。