I have a csv file with delimiter (dot and underscore) and I am using sep='_.' in read_csv but it is not taking dot as sep while reading.
input jks_12034.45_89.12
output jks 12034 45 89 12
CodePudding user response:
As stated in the documentation
separators longer than 1 character and different from '\s ' will be interpreted as regular expressions
If you use sep="_\."
it will only match a point where youhave both an underscore AND a dot.
If you want to split on unserscore OR dot use sep="\.|_"
or sep="[_\.]"
CodePudding user response:
Use engine='python'
and sep=r'[_.]'
as parameters of pd.read_csv
:
df = pd.read_csv('data.csv', sep=r'[_.]', engine='python', header=None)
print(df)
# Output
0 1 2 3 4
0 jks 12034 45 89 12