When using the configuration for automatic separator detection to read csv files (pd.read_csv(file_path, sep=None)
), pandas tries to infer the delimiter (or separat
If all you want to do is detect the dialect of a csv (without loading in your data), you can use the inbuilt csv.Sniffer standard:
The Sniffer class is used to deduce the format of a CSV file.
In particular, the sniff
method:
sniff(sample, delimiters=None)
Analyze the given sample and return a Dialect subclass reflecting the parameters found. If the optional delimiters parameter is given, it is interpreted as a string containing possible valid delimiter characters.
Here's an example of its usage:
with open('example.csv', 'r') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.readline())
print(dialect.delimiter)