I'm reading a huge csv file by iterating over chunks. How can I get the size of the currently processed chunk? Especially the last chunk may have smaller number of rows than defined with the parameter chunksize
.
reader = pd.read_table('myFile.csv', sep=';', chunksize=100)
To read large CSV files in chunks in Pandas, use the read_csv(~) method and specify the chunksize parameter. This is particularly useful if you are facing a MemoryError when trying to read in the whole DataFrame at once.
You can use df. head() to get the first N rows in Pandas DataFrame. Alternatively, you can specify a negative number within the brackets to get all the rows, excluding the last N rows.
You need check length of DataFrame
:
for x in reader:
print (len(x.index))
print (len(x))
print (x.shape[0])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With