Answer the question
In order to leave comments, you need to log in
How to convert txt to csv with given delimiter?
I have a text file input.txt, which contains the following lines:
1 @ 2 @ 3 @ 4 @ 5 @ 6
x @ 123 @ one, two @ 56 @ abc @
y @ 234 @ two; three @ @ abc @
z @ 456 @ three: one @ @ @
1 2 3 4 5 6
x 123 one, two 56 abc NA
y 234 two; three NA abc NA
z 456 three: one NA NA NA
import pandas as pd
df = pd.read_csv('input.txt')
df.to_csv('output.csv', sep='@')
Answer the question
In order to leave comments, you need to log in
When loading from a file, you can specify a delimiter
import pandas as pd
df = pd.read_csv('input.txt', sep='@')
df.to_csv('output.csv')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question