Cut .csv to pieces and save as .csv - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Cut .csv to pieces and save as .csv (/thread-2040.html) |
Converting a bunch of .csv to .txt - BruderKellermeister - May-04-2017 Hi folks, i have a bunch of tab delimited .csv's - which is nice. But now my coworker is telling me, he needs all theese .csv's as .txt since his special Software only accepts .txt. I hope this can't be too dificult, since both formats are textfiles...? The resulting files have to be "tab delimited"... How should i approach this task? here is the code i've gotten my .csv files from (thanks to the folks here that helped me): import pandas as pd df = pd.read_csv('/home/Cutting Excel/Kastanie_Jahrringe.csv', sep=';') for col in df.columns[1:]: if col.endswith('.1'): fname = '/home/Cutting Excel/Cut Pieces/{}.csv'.format(col.replace('.1', 'b')) else: fname = '/home/Cutting Excel/Cut Pieces/{}a.csv'.format(col) df.to_csv(fname, sep='\t', columns=['YEAR', col], index=False, na_rep='NA', header=['YEAR', col.replace('.1', '')]) RE: Converting a bunch of .csv to .txt - buran - May-04-2017 well, just change the extension in your output file from csv to txt. Anyway in the output file you use '\t' as separator. RE: Converting a bunch of .csv to .txt - BruderKellermeister - May-04-2017 ok thanks, ill try that. I will use the codeblock for posting code from now on, but somehow, when i tried in the post above, all the code got messed up (because its formatted with colors i guess...?). RE: Converting a bunch of .csv to .txt - buran - May-04-2017 use Ctrl+Shift+V to paste the code or check BBcode help for more info how to remove the formatting before you submit the post. RE: Converting a bunch of .csv to .txt - Kebap - May-04-2017 (May-04-2017, 09:41 AM)BruderKellermeister Wrote: How should i approach this task? I will merge this thread from 2 hours ago with your other thread about the same issue with your last post from 5 hours ago. |