How to read a file with a semi colon separator in pandas

read_csv takes a sep param, in your case just pass sep=';' like so:

data = read_csv(csv_path, sep=';')

The reason it failed in your case is that the default value is ',' so it scrunched up all the columns as a single column entry.


In response to Morris' question above: "Is there a way to programatically tell if a CSV is separated by , or ; ?"

This will tell you:

import pandas as pd

df_comma = pd.read_csv(your_csv_file_path, nrows=1,sep=",")
df_semi = pd.read_csv(your_csv_file_path, nrows=1, sep=";")
if df_comma.shape[1]>df_semi.shape[1]:
    print("comma delimited")
else:
    print("semicolon delimited")

Tags:

Python

Pandas

Csv