5

I'm trining to read a csv file with Python and Pandas, but my file has a big size (1 GB) so I can't to read all datas. By this web site I learned to use nrows to read rows from my file, for example read first 75 rows, but I can't to read a range of rows.

dts = pd.read_csv('C:\DtsPMU\dts.csv', dtype=float , nrows=75)

This link Python Pandas reads_csv skip first x and last y rows talks to use a code like this:

dts = pd.read_csv('C:\DtsPMU\dts.csv', dtype=float , skiprows=60, nrows=75)

Whit that code I'm try to read just range de rows (start in 60 to 75) but it doen't work.

How could I read range of rows from my csv file?

I'm use Python 3.6.5 and Pandas 0.23.2

2

1 Answer 1

5

This code works fine

dts = pd.read_csv('C:\DtsPMU\dts.csv', dtype=float , skiprows=60, nrows=75)

The only problem is that it makes the row number 60 as the header, if you want the original header then use

names : array-like, default None List of column names to use. If file contains no header row, then you should explicitly pass header=None. Duplicates in this list will cause a UserWarning to be issued.

For example: if your file has 3 columns, then

dts = pd.read_csv('C:\DtsPMU\dts.csv', dtype=float , skiprows=60, nrows=75, names=[0,1,2])
Sign up to request clarification or add additional context in comments.

2 Comments

My file only has a one column I use those code: dts = pd.read_csv('C:\DtsPMU\dts.csv', dtype=float , skiprows=60, nrows=75, names=[0]) dts = pd.read_csv('C:\DtsPMU\dts.csv', dtype=float , skiprows=60, nrows=75, names=[1]) but doesn't work.
Can you show the output or error, whatever you are getting?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.