I have .txt file as next:
Red Blue Green, 1354,8676,38
------------------------------
Yellow Or,ange Black
TU CD CL
0.26 0.265 0.25
-------------------------------
I need to read it. For that purpose, I use pd.read_csv()
and I avoid the last two lines with skipfooter = 2
argument. So, I have:
path_file1 = pathlib.Path.cwd() / ("folder1") / ("file1.txt")
df_folder1 = pd.read_csv(str(path_file1), engine = 'python', index_col = False, skipfooter = 2)
Then, I would like to paste all tha info in other file using .to_csv()
:
path_file2 = pathlib.Path.cwd() / ("folder1") / ("file2.txt")
df_folder2 = df_folder1.to_csv(str(path_file2), index = False, quoting=csv.QUOTE_NONE)
However, I end up with this result:
Red Blue Green, 1354,8676,38
------------------------------,,,
Yellow Or,ange Black,,
TU CD CL,,,
So I cannot get rid of the commas at the end of each line and the empty line is omitted. Is it possible to achieve this using to_csv()
? Should I use csv.writer()
as in this thread?
write csv file with double quotes for particular column not working Is there any chance of specifying a lineterminator?