ekapope / combine-csv-files-in-the-folder Goto Github PK
View Code? Open in Web Editor NEWTiny script to automate everyday task
Home Page: https://medium.com/free-code-camp/how-to-combine-multiple-csv-files-with-8-lines-of-code-265183e0854
Tiny script to automate everyday task
Home Page: https://medium.com/free-code-camp/how-to-combine-multiple-csv-files-with-8-lines-of-code-265183e0854
I have used the code as given and every time I run it, I get more and more rows than I did before but the same number of columns
Hi All,
i am trying below code to read from txt/csv file and writing to csv file. below is the code and csv.writer is appending with double qoutes. can some one help me how to remove double qoutes while writing to csv?
import csv
with open('file.txt') as infile, open('test.csv', 'w', newline='') as outfile:
reader = csv.reader(infile)
for line in (reader):
newline = [','.join(line)]
writer = csv.writer(outfile)
writer.writerow(newline)
"create table script(id number(2),name varchar2(10));"
"create table script1(id number(2),name varchar2(10));"
create table script
(
id number(2)
,name varchar2(10)
);
create table script1
(
id number(2)
,name varchar2(10)
);
1.create table script(id number(2),name varchar2(10));
2.create table script1(id number(2),name varchar2(10));
Hello - I'm fairly new to Python so this might be a stupid question, when I try this code:
`# -- coding: utf-8 --
"""
Created on Sat Jan 12 06:56:16 2019
@author: Chris
"""
#credited:
#https://stackoverflow.com/questions/9234560/find-all-csv-files-in-a-directory-using-python/12280052
import os
import glob
import pandas as pd
#set working directory
os.chdir("C:\Users\chadc\desktop\TEST")
#find all csv files in the folder
#use glob pattern matching -> extension = 'csv'
#save result in list -> all_filenames
extension = 'csv'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
#print(all_filenames)
#combine all files in the list
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames ])
#export to csv
combined_csv.to_csv( "combined_csv.csv", index=False, encoding='utf-8-sig')`
I get this error:
os.chdir("C:\Users\chadc\desktop\TEST")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
And when I run this code:
"""
Created on Sat Jan 12 06:56:16 2019
@author: Chris
"""
#credited:
#https://stackoverflow.com/questions/9234560/find-all-csv-files-in-a-directory-using-python/12280052
import os
import glob
import pandas as pd
#set working directory
os.chdir("\desktop\TEST")
#find all csv files in the folder
#use glob pattern matching -> extension = 'csv'
#save result in list -> all_filenames
extension = 'csv'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
#print(all_filenames)
#combine all files in the list
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames ])
#export to csv
combined_csv.to_csv( "combined_csv.csv", index=False, encoding='utf-8-sig')
I get this error:
Traceback (most recent call last):
File "C:\Users\chadc\Desktop\Combine.py", line 13, in
os.chdir("\desktop\TEST")
FileNotFoundError: [WinError 3] The system cannot find the path specified: '\desktop\TEST'
[Finished in 2.2s]
Using Sublime text editor on Windows 10...
Beautiful code! Thanks!
Your code appended my columns.
I resolved it with:
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames ],axis=1)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.