GeorgeDavidKing
GeorgeDavidKing

Reputation: 149

Pandas read_csv big file puts every column into one

I have a csv file and I'm trying to read it via pandas command read_csv. However instead of reading 5 rows and 21 columns I get the following output: enter image description here

There is a possible solution of manually changing the bad formatting of the file however, the real size is quite big(around 1GB) and it isnt possible to change it manually.

Upvotes: 3

Views: 1316

Answers (1)

harpan
harpan

Reputation: 8631

Consider below solution:

df = pd.read_csv("test.csv", sep="\"\,\"")
data = pd.concat([df.iloc[:,0].str.split(',', expand=True).rename(columns=dict(zip([0,1], df.columns[0].split(',')))), df.iloc[:,1:]], axis=1)

Would return a (5,21) shape of data.

Upvotes: 2

Related Questions