Sridhar Raman
Sridhar Raman

Reputation: 3

how to get data in pandas dataframe skipping 2 rows but also getting some data in first row

I am reading a CSV data from URL The first row contains title which i am not interested but contains date which i need The second row contains headers of the CSV file which I dont need

From 3rd line I have data which I need to read.

I can use Skiprows =2 but I will be unable to get date info from CSV file or is there a way to get date from skipped rows

I tried to read the whole CSV file as data and drop 2 rows. the coumns or not properly formed in first 2 rows and I get error

Is there a way out

Upvotes: 0

Views: 195

Answers (1)

ApplePie
ApplePie

Reputation: 8942

Simply read the first line and then use pandas.read_csv() to get the CSV data:

with open(path) as fd:
    first_line = fd.readline()
    df = pd.read_csv(fd, skiprows=1, header=None)

Upvotes: 1

Related Questions