【发布时间】:2019-11-01 07:25:37
【问题描述】:
我需要遍历文件夹中的所有文件以打开所有 csv 文件。在我得到一个列表中的所有文件目录之后:我需要阅读它们并将它们附加到具有相同列名的数据框中。
a = [] #empty list
for root, dirs, files in os.walk('C:\\Users\\thaiq\\Week5'):
for file in files:
if file.endswith('.csv') and 'Rentals' in file:
a.append(str(os.path.join(root,file)))
ridedata = pd.DataFrame([]) #empty dataframe
for rides in a:
file = pd.read_csv(rides,header=0) #open each file in list a
ridedata.append(file)
ridedata返回空,请帮助:(
【问题讨论】:
-
与python list.append不同,df.append实际上返回的是需要赋值的结果。但除此之外,您应该改用 pd.concat。
标签: python python-3.x