.shape
reymondPurnomo23907433861 total contribution
Published Dec 30, 2022
Contribute to Docs
The .shape
property returns a tuple of information about the dimensions (rows and columns) of a DataFrame object.
Syntax
dataFrameValue.shape
The dataFrameValue
must be a valid DataFrame object. If the dataFrameValue
has a different length for one or more columns, a ValueError
will be thrown.
Example
The following example initiates a DataFrame and uses .shape
to return the number of rows and columns:
import pandas as pdd = {"col1" : [1, 2 ,3], "col2" : [4, 5, 6]}df = pd.DataFrame(data = d)print(df.shape)
This will print the following:
(3, 2)
The result can be interpreted that DataFrame has 3 rows and 2 columns.
Codebyte Example
The following example throws a ValueError
because the DataFrame has columns of differing length:
All contributors
- reymondPurnomo23907433861 total contribution
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.