【发布时间】:2019-01-05 02:03:58
【问题描述】:
我浏览了网站上的所有帖子,但无法找到解决问题的方法。
我有一个包含 15 列的数据框。其中一些带有None 或NaN 值。我需要帮助来编写 if-else 条件。
如果数据框中的列不为 null 和 nan,我需要格式化 datetime 列。当前代码如下
for index, row in df_with_job_name.iterrows():
start_time=df_with_job_name.loc[index,'startTime']
if not df_with_job_name.isna(df_with_job_name.loc[index,'startTime']) :
start_time_formatted =
datetime(*map(int, re.split('[^\d]', start_time)[:-1]))
我得到的错误是
if not df_with_job_name.isna(df_with_job_name.loc[index,'startTime']) :
TypeError: isna() takes exactly 1 argument (2 given)
【问题讨论】:
-
谢谢我尝试使用 null_map_df = df_with_job_name.isna()。它适用于少量测试记录。但是,当我在此数据框中迭代 700 多个项目时,它为 nan 值之一返回 false