python
Get the count of rows and columns of a Pandas DataFrame
You can use DataFrame.shape to get the total number of rows and columns that exists in a Pandas DataFrame.
import pandas as pd
data = {
"subjects": ["Math", "Physics", "Chemistry", "English", "Hindi"],
"scores": [90, 80, 87, 80, 70]
}
df = pd.DataFrame(data)
# Get rows and columns count
result = df.shape
print("Rows: ", result[0])
print("Columns: ", result[1])
Output
Rows: 5
Columns: 2
DataFrame.shape returns a tuple that contains two integer type values. The first value is the count of Rows in the DataFrame and the second value is the total number of Columns in the DataFrame.
Was this helpful?
Similar Posts
- Create pandas DataFrame and add columns and rows to it
- Sort a DataFrame by rows and columns in Pandas
- Count NaN values in a Pandas DataFrame
- Count Rows group by column name SqlAlchemy
- Get a column rows as a List in Pandas Dataframe
- Get all rows that contain a substring in Pandas DataFrame
- Reorder dataframe columns using column names in pandas