小编Jac*_*uer的帖子

在python中使用pandas将csv文件附加到一个

我在一个目录中有n个文件需要合并为一个.它们具有相同数量的列,例如,内容test1.csv是:

test1,test1,test1  
test1,test1,test1  
test1,test1,test1  
Run Code Online (Sandbox Code Playgroud)

同样,内容test2.csv是:

test2,test2,test2  
test2,test2,test2  
test2,test2,test2  
Run Code Online (Sandbox Code Playgroud)

我希望final.csv看起来像这样:

test1,test1,test1  
test1,test1,test1  
test1,test1,test1  
test2,test2,test2  
test2,test2,test2  
test2,test2,test2  
Run Code Online (Sandbox Code Playgroud)

但相反它出来是这样的:

test file 1,test file 1.1,test file 1.2,test file 2,test file 2.1,test file 2.2  
,,,test file 2,test file 2,test file 2  
,,,test file 2,test file 2,test file 2  
test file 1,test file 1,test file 1,,,  
test file 1,test file 1,test file 1,,,  
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄清楚这里发生了什么吗?我在下面粘贴了我的代码:

import csv
import glob
import pandas as pd
import numpy as np 

all_data = pd.DataFrame() #initializes DF which …
Run Code Online (Sandbox Code Playgroud)

python csv pandas

5
推荐指数
1
解决办法
2101
查看次数

标签 统计

csv ×1

pandas ×1

python ×1