sagargahalod
sagargahalod

Reputation: 19

How to read CSV where data start stored in one of the columns only?

I have CSV file like below:

So first row contains all the columns without comma separation and second row has the data in the first column with comma separation

COLID                 TEMP1        TEMP2        TEMP3  .....
1,20.1,40.2,8.5

how to read and bring it in

COLID TEMP1  TEMP2  TEMP3
1      20.1  40.2    8.5

dataframe format .

Upvotes: 0

Views: 45

Answers (1)

Utsav
Utsav

Reputation: 5918

Here, I have named file to be read as text.csv.

Important thing is 'sep' argument where we are telling pandas to read csv which is separated by spaces(\s+) or comma or a tab(\t).

pd.read_csv('test.csv', engine='python', sep='\s+|,|\t')

Output

    COLID   TEMP1   TEMP2   TEMP3
0   1       20.1    40.2    8.5

Upvotes: 1

Related Questions