I have a csv file that has only one column. I want to extract the number of rows. When I run the the code below:
import pandas as pd
df = pd.read_csv('data.csv')
print(df)
I get the following output:
[65422771 rows x 1 columns]
But when I run the code below:
file = open("data.csv")
numline = len(file.readlines())
print (numline)
I get the following output:
130845543
What is the correct number of rows in my csv file? What is the difference between the two outputs?
df.shape[0]return?read_csvthe parameterskip_blank_linesisTRUEby default I'm guessing you have many blank lines in the CSV file, per @Giovannirison's answer below. An answer to this is going to need a sample of what is in the CSV?