简体   繁体   中英

How do I read only a specific column and a specific row from a .csv file in Python?

I have a csv file that has arrays in two columns and I would like to read those for a specific row. How do I do that?

So far, I have:

pd.read_csv('file_name.csv', usecols= [23], nrows=3)

But this reads every row below what is skipped and I don't want that.

Thank you!

If you now the row number you want to read you can use the skiprows argument and then get a single row with nrows=1 argument.

pd.read_csv('file_name.csv', usecols=[23], nrows=1, skiprows=3)

I hope I was useful:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM