One - One Code All

Blog Content

Dataframe的总行数和总列数大小多少汇总统计shape,len,index,count

Python 统计学-科学计算   2016-05-22 22:33:36

可以使用.shape属性或者len(DataFrame.index)。 但是,有明显的性能差异(.shape属性更快):


返回列数:

df.shape[1]

返回行数:

df.shape[0]

或者:

len(df)

len(df.index)

df[0].count()

df.index.size更快

使用可以使用df.axes来获取行列索引的元组,然后使用len()函数:

total_rows=len(df.axes[0])

total_cols=len(df.axes[1])



上一篇:Python字典dictionary changed size during iteration
下一篇:flask-sqlalchemy中,将查询语句转换成原始SQL打印

The minute you think of giving up, think of the reason why you held on so long.