简体   繁体   中英

How do I combine CSV Files?

I'm trying to combine 12 CSV files together using the below code, but keep getting the error "FileNotFoundError: [Errno 2] No such file or directory: '/Users/RW/Desktop/London_Crime_Data'"

csv_filepath = '/Users/RW/Desktop/London_Crime_Data'
os.chdir(csv_filepath)
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
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')

Can anyone help me?

If the path is meant to be relative (starting in current directory and ascending into it), you should try removing the leading '/'. If the path is absolute and you are on Windows, you might want to add the drive letter. That are the options I can think of.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM