Methd 1: Use len()
You can use len(df.index)
to check the number of row in Python Pandas dataframes.
import pandas as pd
car_data = {'Brand': ['Tesla', 'Tesla','Tesla','Ford','Ford','Ford','Toyota','Toyota'],
'Location': ['CA', 'CA','NY','MA','CA','WA','CA','TX'],
'Year':['2019','2018','2020','2019','2016','2010','2018','2021']}
car_data=pd.DataFrame(data=car_data)
print(car_data)
Brand Location Year 0 Tesla CA 2019 1 Tesla CA 2018 2 Tesla NY 2020 3 Ford MA 2019 4 Ford CA 2016 5 Ford WA 2010 6 Toyota CA 2018 7 Toyota TX 2021
len(car_data.index)
8
Method 2: Use df.shape
You can use df.shape
to check the number of rows in Python Pandas dataframes.
car_data.shape
(8, 3)
car_data.shape[0]
8