problem with column separation in csv file

78 Views Asked by At

i'm using panda and i have problem with separation. In the csv file the separator is '|'

df=pd.read_csv('C:/dane/raport_d.csv',encoding='ansi',low_memory=False,sep='|')
df.head() 

After executing the code, I only see the headers, not separated by a separator, and the same data
other csv files where the separator is "," I have no problem

enter image description here

2

There are 2 best solutions below

1
Muhammad Nasir On

you can change the delimiter by tab,

df=pd.read_csv('C:/dane/raport_d.csv', sep="\t")

and if you get the unicode error,then

df=pd.read_csv('C:/dane/raport_d.csv', sep="\t", index=False, encoding='utf-8')
1
Grzegorz Z On

I found the solution by adding quotechar="'". But now my dataframe looks enter image description here

how to remove all these double quotes? data = df.replace('"', '', regex=True) it's working but still i have double quotes in the headlines