Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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追加到另一个CSV_Python_Pandas_Csv_Merge_Dataset - Fatal编程技术网

在Python中将行从一个CSV追加到另一个CSV

在Python中将行从一个CSV追加到另一个CSV,python,pandas,csv,merge,dataset,Python,Pandas,Csv,Merge,Dataset,我已经研究了很多解决方案,但找不到一个适合我想做的 基本上我有2个CSV文件: all.csv 原件.csv 我想将original.csv附加到all.csv,只需将original.csv中的所有行合并到all.csv的最后一行下面即可获得: 1 Wed Oct 03 41.51093923 41.51093923 41.51093923 41.51093923 2 Wed Oct 04 3 Wed Oct

我已经研究了很多解决方案,但找不到一个适合我想做的

基本上我有2个CSV文件:

all.csv

原件.csv

我想将
original.csv
附加到
all.csv
,只需将
original.csv
中的所有行合并到
all.csv
的最后一行下面即可获得:

1   Wed Oct 03  41.51093923 41.51093923 41.51093923 41.51093923         
2   Wed Oct 04                          
3   Wed Oct 05  41.43764015 41.43764015 41.43764015             
4   Wed Oct 06  41.21395681 41.21395681 41.21395681             
5   Wed Oct 07  42.07607442 42.07607442 42.07607442             
6   Wed Oct 08  42.0074109  42.0074109  42.0074109              
7   Wed Oct 09  41.21395681 41.21395681                 
8   Wed Oct 10  41.43764015 41.43764015 41.43764015 41.43764015 
9   Wed Oct 11  41.21395681 41.21395681 41.21395681 41.21395681
10  Wed Oct 12  41.43764015             
11  Wed Oct 13                  
12  Wed Oct 14  42.07607442 42.07607442 42.07607442     
13  Wed Oct 15  41.43764015 41.43764015 41.43764015 41.43764015
14  Wed Oct 16  41.21395681 41.21395681 41.21395681 41.21395681
15  Wed Oct 17                  
16  Wed Oct 18  42.07607442 42.07607442 42.07607442 
如您所见,数据没有标题,行的长度也不同。这只是我正在处理的文件类型的一个示例,但我想得到一个可以处理任何CSV的解决方案

我正在使用Python3,到目前为止,我已经尝试使用
pandas
库,但没有成功


任何建议都很好,谢谢。

您不需要使用
pandas
。只需将一个csv附加到另一个csv:

with open('original.csv', 'r') as f1:
    original = f1.read()

with open('all.csv', 'a') as f2:
    f2.write('\n')
    f2.write(original)
输出:

1   Wed Oct 03  41.51093923 41.51093923 41.51093923 41.51093923
2   Wed Oct 04
3   Wed Oct 05  41.43764015 41.43764015 41.43764015
4   Wed Oct 06  41.21395681 41.21395681 41.21395681
5   Wed Oct 07  42.07607442 42.07607442 42.07607442
6   Wed Oct 08  42.0074109  42.0074109  42.0074109
7   Wed Oct 09  41.21395681 41.21395681
8   Wed Oct 10  41.43764015 41.43764015 41.43764015 41.43764015
9   Wed Oct 11  41.21395681 41.21395681 41.21395681 41.21395681
10  Wed Oct 12  41.43764015
11  Wed Oct 13
12  Wed Oct 14  42.07607442 42.07607442 42.07607442
13  Wed Oct 15  41.43764015 41.43764015 41.43764015 41.43764015
14  Wed Oct 16  41.21395681 41.21395681 41.21395681 41.21395681
15  Wed Oct 17
16  Wed Oct 18  42.07607442 42.07607442 42.07607442

在使用熊猫时,您是否可以显示您在这方面的尝试
with open('original.csv', 'r') as f1:
    original = f1.read()

with open('all.csv', 'a') as f2:
    f2.write('\n')
    f2.write(original)
1   Wed Oct 03  41.51093923 41.51093923 41.51093923 41.51093923
2   Wed Oct 04
3   Wed Oct 05  41.43764015 41.43764015 41.43764015
4   Wed Oct 06  41.21395681 41.21395681 41.21395681
5   Wed Oct 07  42.07607442 42.07607442 42.07607442
6   Wed Oct 08  42.0074109  42.0074109  42.0074109
7   Wed Oct 09  41.21395681 41.21395681
8   Wed Oct 10  41.43764015 41.43764015 41.43764015 41.43764015
9   Wed Oct 11  41.21395681 41.21395681 41.21395681 41.21395681
10  Wed Oct 12  41.43764015
11  Wed Oct 13
12  Wed Oct 14  42.07607442 42.07607442 42.07607442
13  Wed Oct 15  41.43764015 41.43764015 41.43764015 41.43764015
14  Wed Oct 16  41.21395681 41.21395681 41.21395681 41.21395681
15  Wed Oct 17
16  Wed Oct 18  42.07607442 42.07607442 42.07607442