我想从网络文件夹中找到所有.gz文件的文件夹路径。
我在script以下,但给出了error

TypeError: cannot concatenate a non-NDFrame object


请帮忙

脚本:

import os
import pandas as pd

adcPath = r'\\ADC\redshift-datasets\BLSCEWAG2016'

gzPath = pd.DataFrame(columns=['Path'], dtype=object)
for path, subdirs, files in os.walk(adcPath):
for name in files:
if name.endswith('.gz'):
gzPath = gzPath.append(path) # Want to insert to dataframe gzPath to export in csv

gzPath = gzPath['Path'].unique()
exportPath = r'D:\Sunil_Work\temp8' + '\\Path.csv'
gzPath.to_csv(exportPath)

最佳答案

您可以在glob模块中使用glob函数来获取所有.gz文件:

import glob
files = glob.glob(r'\\ADC\redshift-datasets\BLSCEWAG2016\**\*.gz', recursive=True)


然后,创建数据框并调用df.unique

gzPath = pd.DataFrame(files, columns=['Path'], dtype=object)['Path'].unique()


保存到csv:

exportPath = r'D:\Sunil_Work\temp8' + '\\Path.csv'
gzPath.to_csv(exportPath)

10-07 19:08
查看更多