Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python读取多个csv文件并转换为数据帧_Python_Pandas_List - Fatal编程技术网

Python读取多个csv文件并转换为数据帧

Python读取多个csv文件并转换为数据帧,python,pandas,list,Python,Pandas,List,我试图从不同的文件夹中读取多个格式相同的.csv文件。结果是一个使用.append的列表,我尝试使用.concat将其转换为数据帧。但它不让我这么做。我还尝试了.os来读取数据。这是行不通的。有什么建议吗 test = [] train = [] for f in testdata: test.append(pd.read_csv(f, skiprows = 5, sep = ',', names = ['time','avg_rss12','var_rss12','

我试图从不同的文件夹中读取多个格式相同的.csv文件。结果是一个使用.append的列表,我尝试使用.concat将其转换为数据帧。但它不让我这么做。我还尝试了.os来读取数据。这是行不通的。有什么建议吗

test = []
train = []
for f in testdata:
    test.append(pd.read_csv(f, skiprows = 5, sep = ',', names = 
         ['time','avg_rss12','var_rss12','avg_rss13','var_rss13','avg_rss23','var_rss23']))
for f in traindata:
    train.append(pd.read_csv(f, skiprows = 5, sep = ',', names = 
         ['time','avg_rss12','var_rss12','avg_rss13','var_rss13','avg_rss23','var_rss23']))

您提到了尝试使用
concat
,但没有说明失败的原因。这是你想走的路。仅使用问题中的测试循环:

import pandas as pd


frames = []
for f in testdata:
    df = pd.read_csv(f, skiprows=5, sep=',', names=['time','avg_rss12','var_rss12','avg_rss13','var_rss13','avg_rss23','var_rss23'])
    frames.append(df)
combined = pd.concat(frames)

传递到
concat()
的内容需要是一个数据帧实例列表,它将把这些实例组合成一个单独的帧。

哪些内容不适用于
pd.concat()
?如果所有的框架都是相同的模式,那么这是解决问题的正确方法。是否指定了要沿哪个轴执行连接?我认为行是默认的轴。