Write a pandas program to count the rows and columns.
Output
No of rows: 4
No of columns: 2
Approach
shape.
Solution
Python
importpandasaspddf=pd.DataFrame({"name":["Alex","John","Peter","Klaus"],"age":[30,27,29,33]})rows,cols=df.shapeprint("No of rows:",rows)print("No of columns:",cols)
Output
No of rows: 4
No of columns: 2
Learn the concept
New to this topic? Read the lesson, then come back.