Jan Rostenkowski
Jan Rostenkowski

Reputation: 325

read_csv not separating columns in given txt file

My input txt file looks like this:

2019-06-23 17:53                                                  Page 1


1.9752838,1.9752001,1.9752001,1.9749992,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017
1.9752017,1.9752017,1.9752017,1.9752017,1.9752989,1.9752471,1.9751560,1.9751560,1.9753192,1.9752765,1.9752767,1.9644918
1.9754473,1.9751872,1.9751872,1.9745865,1.9753944,1.9753007,1.9750204,1.9750204,1.9754550,1.9754478,1.9754481,1.9518886
1.9753613,1.9751965,1.9751965,1.9747815,1.9754874,1.9753416,1.9747925,1.9747925,1.9755443,1.9756079,1.9756084,1.9574568
1.9752838,1.9752001,1.9752001,1.9754132,1.9752989,1.9752471,1.9751559,1.9751560,1.9750417,1.9752768,1.9752767,1.9816657
1.9754473,1.9751873,1.9751873,1.9758274,1.9753945,1.9753007,1.9750204,1.9750204,1.9749107,1.9754483,1.9754481,1.9861361
1.9753612,1.9751966,1.9751966,1.9756361,1.9754875,1.9753416,1.9747925,1.9747926,1.9746301,1.9756088,1.9756084,1.9894820

When I do

df = pd.read_csv('/Users/jan/data/ofile.csv', sep = ",")

The output dataframe has all the values organized in the way one might expect, except all the values are in one single column, confirmed by the command below.

len(df.columns) 
1

How can I make it so that the dataframe sees the columns? I tried playing around with the 'header' tag and reading it as a txt file instead of csv, but nothing solved the problem. I know this has been asked repeatedly before but nothing seemed to solve my problem.

Upvotes: 0

Views: 106

Answers (1)

BENY
BENY

Reputation: 323396

Check with skiprows

pd.read_csv('/Users/jan/data/ofile.csv', skiprows=3, header=None, sep=',')

Upvotes: 1

Related Questions