St123
St123

Reputation: 320

Pandas read csv fails

Given a text file (.txt) containing comma seperated values such as 6,3,2,6,3,7,6,4,... I want to read the integer values to a pandas data frame with the method .read_csv.

import pandas as pd

data_frame = pd.read_csv(csv_config['path'], sep=",")

The resulting values are stored in data_frame.columns and look like this: 6, 3, 2, 6.1, 3.1, 7, 6.2, 4, ...

Where do the float values come from, when I expected Integer values?

Upvotes: 1

Views: 97

Answers (1)

pnovotnyq
pnovotnyq

Reputation: 547

Pandas assign a unique name to each column. So the first occurence of 6 has a column name "6", the second has "6.1" etc. Note that they are strings rather than floats.

If you want to read the first row as values (instead of column headers), you should do:

df = pd.read_csv(csv, header=None)

Upvotes: 2

Related Questions