pandas read csv with extra commas in column

后端 未结 2 1496
执念已碎
执念已碎 2020-12-05 20:07

I\'m reading a basic csv file where the columns are separated by commas with these column names:

userid, username, body

However, the body column

2条回答
  •  一生所求
    2020-12-05 20:30

    Imagine we're reading your dataframe called comma.csv:

    userid, username, body
    01, n1, 'string1, string2'
    

    One thing you can do is to specify the delimiter of the strings in the column with:

    df = pd.read_csv('comma.csv', quotechar="'")
    

    In this case strings delimited by ' are considered as total, no matter commas inside them.

提交回复
热议问题