import pandas as pd
df = pd.read_csv('JOB205DAYREP.csv', header=0)
df = df.drop([0],axis=0)
df = df.dropna(axis=0, how='all')
df = df.dropna(axis=1, how='all')
df.head(10)
df = pd.DataFrame({})
from dateutil.parser import parse
for index, row in df.iterrows():
if pd.isnull(row['FLT']) or row ['FLT'] == 'NA':
df.at[index, 'FLT'] = df.at[index-1, 'FLT']
if pd.isnull(row['STD']) or row ['STD'] == 'NA':
df.at[index,'STD'] = df.at[index-1, 'STD']
else:
row['STD'] = fltdate + row ['STD']
if not index==0 :
if pd.isnull(row['VIAOFF']) or row['VIAOFF'] == 'NA':
df.at[index, 'VIAOFF'] = df.at[index-1, 'VIAOFF']
if pd.isnull(row['DEP']) or row['DEP'] == 'NA':
df.at[index, 'DEP'] = df.at[index-1, 'DEP']
df.head(10)
from dateutil.parser import parse
date_string = '21/01/2023'
try :
if parse(date_string, fuzzy=True, dayfirst=True) is not None:
print('The string is a valid date.')
else:
print('The string is not a valid date.')
except Exception as e:
error ='error'
此代码使用**pandas
模块中的read_csv()
**函数阅读CSV文件,并删除第一行、所有包含缺失值的行以及所有包含缺失值的列。
Here is the csv data
Output
2条答案
按热度按时间1u4esq0p1#
名称错误:name 'df' is not defined(名称'df'未定义)错误,因为df DataFrame被重新分配给第10行中的空DataFrame:
你可以把它去掉
如果现在起作用了就报告,希望能有所帮助。
wkyowqbh2#
应为“read_csv”。打字错误。