1

I have some problems with reading CSV file into DataFrame. My CSV file is machine-stored file with several lines of file and data info in front of data table, as shown below:

! Software: xyz
! Testplan: C:\Software\abc
! Probe Plan: abc
! Software: xyz
! Datafile: C:\Software\data.CSV
! Description: data
Name, Location, Price, Quantity, 
Jack, New York, 39, 20,
Tom, Los Angeles, 35, 18,
Carl, San Jose, 48, 22,
Jean, Dallas, 59, 11,

I would like to skip the characters and only read the data table into DataFrame. In addition, read the column names as the head of DataFrame.

So the desired DataFrame is like below:

Column Head: Name Location Price Quantity Jack New York 39 20 Tom Los Angeles 35 18 Carl San Jose 48 22 Jean Dallas 59 11

How I can do that?

0

1 Answer 1

1

I think you can just skip the rows using the skiprows argument of pd.read_csv:

df = pd.read_csv('filename.csv', skiprows=6)

   Name      Location   Price   Quantity    
0  Jack      New York      39         20 NaN
1   Tom   Los Angeles      35         18 NaN
2  Carl      San Jose      48         22 NaN
3  Jean        Dallas      59         11 NaN
1
  • 2
    or comment ='!'
    – jezrael
    May 8, 2018 at 15:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.