0

I am playing with famous titanic data. I have data csv with comma separation. And data looks like this:

passengerId,survived,pclass,name,sex,age,sibSp,parch,ticket,fare,cabin,embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C

I am trying to use pandas.csv_read but it doesn't work.

My code:

import pandas as pd

titanic = pd.read_csv('titanic.csv')
print(titanic.head(10))

I tried couple combinations with argues of the csv_read method: sep = ',', decimal = ',', delimiter = ',' and still I got the same output which is:

                                         passengerId  survived  ...  cabin  embarked
0  1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/...       NaN  ...    NaN       NaN
1  2,1,1,"Cumings, Mrs. John Bradley (Florence Br...       NaN  ...    NaN       NaN
2  3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,S...       NaN  ...    NaN       NaN

I tryied to search in other stackoverflow questions but I couldn't find an answer. Thank you for your help.

Karollo
  • 45
  • 7

1 Answers1

0

It seems like the problem is that you have some commas inside your columns.

The quotechar parameter might help you since it will tell pandas to ignore commas between the char specified (")

titanic = pd.read_csv('titanic.csv', quotechar='"', sep=",")
Placeprom
  • 64
  • 7