import pandas as pd
df = pd.DataFrame([[1, ‘A‘, ‘3%‘ ], [2, ‘B‘]], index=[‘row_0‘, ‘row_1‘], columns=[‘col_0‘, ‘col_1‘, ‘col_2‘])
shape = df.shape
rows = shape[0]
或
rows = len(df.index)
cols = df.shape[1]
或
cols = len(df.columns)
其中df.index和df.columns是df的行索引和列索引,类型是‘object’型,可以适用len()方法。
原文:https://www.cnblogs.com/HL-space/p/10656046.html