【发布时间】:2017-05-08 20:24:57
【问题描述】:
我遇到了 Pandas 数据框的问题。 似乎 Pandas/Python 在我的代码中的某处生成了 DF 的副本,而不是对原始 DF 进行修改。
在下面的代码中,“update_df”仍然看到带有“file_exists”列的 DF,该列应该已被前面的函数删除。
主要:
if __name__ == '__main__':
df_main = load_df()
clean_df2(df_main)
update_df(df_main, image_path_main)
.....
clean_df2
def clean_df2(df): #remove non-existing files from DF
df['file_exists'] = True # add column, set all to True?
.....
df = df[df['file_exists'] != False] #Keep only records that exist
df.drop('file_exists', 1, inplace=True) # delete the temporary column
df.reset_index(drop=True, inplace = True) # reindex if source has gaps
update_df:
def update_df(df, image_path): #add DF rows for files not yet in DF
print(df)
....
【问题讨论】: