• Register
1 vote
20 views

Problem:

Hello guys, I have a big number of .csv file with full of data. I want to merge them all in a single file. It is a hectic job to copy all the data from each and compile into one single file. So, I am willing to combine multiple .csv files into one using a python program. Could anybody please help me to do it.

Thanks for your effort guys.

Note: I named all the .csv files under a series. Let say they are named with data1-data100

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

Let me assume, you want to merge all the data from other files into the first file data1.csv file. So, you need to open the first file and then copy all the data from others and gather it into the first file.

fout=open("out.csv","a")
for line in open("data1.csv"):
    fout.write(line)
for num in range(2,100):
    f = open("data"+str(num)+".csv")
    f.next()
    for line in f:
         fout.write(line)
    f.close()
fout.close()

GIve it a try and leave a comment below my answer if you have not overcome the problem.
Thanks

13 9 6
94,260 points

Related questions

0 votes
1 answer 8 views
8 views
Problem: I am getting trouble with the following line:how to read from csv file in python.
asked Apr 12 ashik 14.6k points
0 votes
1 answer 4 views
4 views
Problem: Can someone explain to me as to why am I getting the above error message:python read csv file line by line
asked Apr 12 ashik 14.6k points
1 vote
1 answer 5 views
5 views
Problem : I like to learn > How to read a CSV file into a .NET Datatable
asked Apr 25 Abik Dey 4k points
0 votes
1 answer 7 views
7 views
Problem: Can some please show me the easiest way to solve this problem,"Load a csv file into mysql via php"?
asked Apr 16 Supti 13k points
0 votes
1 answer 3 views
3 views
Problem I'm having a bit of a problem trying to import data from a CSV and have a couple of questions on it that I haven't managed to solve myself yet.
asked Apr 7 neeraj 10.5k points
0 votes
1 answer 29 views
29 views
I need to export my SQL information to a csv file so that I can attached this file to email. But the code below is not working. I have two main concerns. There is no line break even I used the “\n”. The exported csv file is empty. $servername = " ... ,time()).".csv"; $csv_file = fopen ($csv_filename, "w"); echo $csv_Content; fclose($csv_file); Please help me to make this code working.
asked Oct 23, 2020 azriel 590 points
0 votes
1 answer 16 views
16 views
Is there any PHP code snippet that demonstrate on how to import a csv file to MySql database?
asked Oct 22, 2020 azriel 590 points
0 votes
1 answer 29 views
29 views
I need to import a csv file that was generated by the system for me to import and save it to the database. But it generated an error “array_combine(): Both parameters should have an equal number of elements”. I was trying to debug my code but not able to see what cause ... $my_array[] = array_combine($keys, $data); } } fclose($csv); } /* if (($csv !== false) { }*/ return $my_array; }
asked Oct 12, 2020 robin_gallo 420 points
0 votes
1 answer 37 views
37 views asked Oct 24, 2020 Shaad Sh 800 points
0 votes
1 answer 103 views
103 views
Hi, I need to save to my database from the csv file. My csv contains similar information in the code that I included here. "Last name", "First name", "SSN", "Test1", "Test2", "Test3", "Test4", "Final", "Grade" "Alfalfa", "Aloysius", "123-45-6789", 40.0, 90.0, 100.0, 83.0, 49.0, "D-" "Alfred", ... .0, 97.0, 96.0, 97.0, 48.0, "D+" "Gerty", "Gramma", "567-89-0123", 41.0, 80.0, 60.0, 40.0, 44.0, "C"
asked Oct 12, 2020 robin_gallo 420 points