JamesArthur
JamesArthur

Reputation: 506

Csv from Kaggle puts all columns into 1 - how to separate with pd.read_csv and make usable df

I just downloaded this CSV from kaggle

https://www.kaggle.com/psvishnu/bank-direct-marketing?select=bank-full.csv

However, when it downloads, all the 17 or so columns are in 1, so when I use

df = pd.read_csv('bank-full.csv)

it too has all values in one column.

Any thoughts would be great, I haven't come across this issue before, thanks!

df sample

58;"management";"married";"tertiary";"no";2143;"yes";"no";"unknown";5;"may";261;1;-1;0;"unknown";"no"
0     44;"technician";"single";"secondary";"no";29;"yes";"no";"unknown";5;"may";151;1;-1;0;"unknown";"no"
1   33;"entrepreneur";"married";"secondary";"no";2;"yes";"yes";"unknown";5;"may";76;1;-1;0;"unknown";"no"
2    47;"blue-collar";"married";"unknown";"no";1506;"yes";"no";"unknown";5;"may";92;1;-1;0;"unknown";"no"
3            33;"unknown";"single";"unknown";"no";1;"no";"no";"unknown";5;"may";198;1;-1;0;"unknown";"no"
4    35;"management";"married";"tertiary";"no";231;"yes";"no";"unknown";5;"may";139;1;-1;0;"unknown";"no"
5    28;"management";"single";"tertiary";"no";447;"yes";"yes";"unknown";5;"may";217;1;-1;0;"unknown";"no"
6  42;"entrepreneur";"divorced";"tertiary";"yes";2;"yes";"no";"unknown";5;"may";380;1;-1;0;"unknown";"no"
7         58;"retired";"married";"primary";"no";121;"yes";"no";"unknown";5;"may";50;1;-1;0;"unknown";"no"
8     43;"technician";"single";"secondary";"no";593;"yes";"no";"unknown";5;"may";55;1;-1;0;"unknown";"no"
9      41;"admin.";"divorced";"secondary";"no";270;"yes";"no";"unknown";5;"may";222;1;-1;0;"unknown";"no"

Upvotes: 0

Views: 207

Answers (2)

imxitiz
imxitiz

Reputation: 3987

You can do this:

import pandas as pd

df=pd.read_csv("<filename.csv>",sep=";") #Or you may use delimiter=";"
print(df)

Your file's columns are separated by ; so we assigned separator as ;.

You can get further more information about read_csv from documentation.

Upvotes: 1

Jung Hyuk Lee
Jung Hyuk Lee

Reputation: 21

you can use delimiter argument for read_csv function to set the character for separation as

df = pd.read_csv('bank-full.csv', delimiter=';')

Upvotes: 0

Related Questions