Python import CSV short code (pandas?) delimited with ';' and ',' in entires
Question: I need to import a CSV file in Python on Windows. My file is delimited by ';'
and has strings with non-English symbols and commas (',').

I've read posts:

[Importing a CSV file into a sqlite3 database table using
Python](http://stackoverflow.com/questions/2887878/importing-a-csv-file-into-
a-sqlite3-database-table-using-python)

[Python import csv to
list](http://stackoverflow.com/questions/24662571/python-import-csv-to-list)

When I run:

    
    
    with open('d:/trade/test.csv', 'r') as f1:
        reader1 = csv.reader(f1)
        your_list1 = list(reader1)
    

I get an issue: comma is changed to '-' symbol.

When I try:

    
    
    df = pandas.read_csv(csvfile)
    

I got errors:

> pandas.io.common.CParserError: Error tokenizing data. C error: Expected 1
> fields in line 13, saw 2.

Please help. I would prefer to use pandas as the code is shorter without
listing all field names from the CSV file.

I understand there could be the work around of temporarily replacing commas.
Still, I would like to solve it by some parameters to pandas.


Answer: Unless your CSV file is broken, you can try to make `csv` guess your format.

    
    
    import csv
    
    with open('d:/trade/test.csv', 'r') as f1:
        dialect = csv.Sniffer().sniff(f1.read(1024))
        f1.seek(0)
        r = csv.reader(f1, dialect=dialect)
        for row in r:
            print(row)
    

