Answers for "pandas access specific row in csv"

0

pandas how to start read csv at a certain row

import pandas as pd
# Select file 
infile = r'path/file'
# Use skiprows to choose starting point and nrows to choose number of rows
data = pd.read_csv(infile, skiprows = 50, nrows=10)
Posted by: Guest on July-27-2021
0

read specific rows from csv in python

You could use a list comprehension to filter the file like so:

with open('file.csv') as fd:
    reader=csv.reader(fd)
    interestingrows=[row for idx, row in enumerate(reader) if idx in (28,62)]
# now interestingrows contains the 28th and the 62th row after the header
Posted by: Guest on March-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language