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 separator).
Is there a way to retrieve the result of this inference (the value that was finally used for sep
)?
EDIT
I am looking specifically for a method that uses the pandas object that is returned by read_csv
. I use version 0.20.2 of pandas.
read_csv(filepath_or_buffer, sep=', ', delimiter=None, header='infer', names=None, index_col=None, ....) It reads the content of a csv file at given path, then loads the content to a Dataframe and returns that. It uses comma (,) as default delimiter or separator while parsing a file.
Using the "From Text" feature in Excel Select the CSV file that has the data clustered into one column. Select Delimited, then make sure the File Origin is Unicode UTF-8. Select Comma (this is Affinity's default list separator). The preview will show the columns being separated.
read_csv() method. We have to import pandas library to use this method. This method uses comma ', ' as a default delimiter but we can also use a custom delimiter or a regular expression as a separator.
I think you can do this without having to import csv
:
reader = pd.read_csv(file_path, sep = None, iterator = True)
inferred_sep = reader._engine.data.dialect.delimiter
EDIT:
Forgot the iterator = True
argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With