Python 删除条件包含(os.path.exists)的数据帧
正在尝试删除路径不存在的行Python 删除条件包含(os.path.exists)的数据帧,python,pandas,Python,Pandas,正在尝试删除路径不存在的行 data_docs = pd.read_csv('Documents_data.csv') data_docs.drop(data_docs[os.path.exists(str(data_docs['file path']))].index, inplace=True) 错误: KeyError: False 目前,os.path.exists查看列的整个str表示,而不是逐个元素。一种方法是应用: exists=data_docs[“文件路径”].apply(
data_docs = pd.read_csv('Documents_data.csv')
data_docs.drop(data_docs[os.path.exists(str(data_docs['file path']))].index, inplace=True)
错误:
KeyError: False
目前,
os.path.exists
查看列的整个str
表示,而不是逐个元素。一种方法是应用:
exists=data_docs[“文件路径”].apply(os.path.exists)
数据文档=数据文档[存在]
如果打印exists
,它将是一个布尔序列,说明哪些路径存在,哪些不存在
exists = ~exists
data_docs.drop(data_docs[exists].index, inplace=True)
反向存在
删除结果为假的,
现在它将删除不存在的文件