如何获取 Pandas DataFrame 的行数?
若要获取 Pandas DataFrame 的行数,我们可以使用 DataFrame 索引长度。
步骤
创建一个二维可变大小的异构表格数据,即**df**。
打印输入的 DataFrame。
打印 DataFrame 索引列表的长度,即 **len(df.index)**。
示例
import pandas as pd
df = pd.DataFrame(
{
"x": [5, 2, 1, 9],
"y": [4, 1, 5, 10],
"z": [4, 1, 5, 0]
}
)
print "Input DataFrame is:
", df
print "Row count of DataFrame is: ", len(df.index)输出
Input DataFrame is: x y z 0 5 4 4 1 2 1 1 2 1 5 5 3 9 10 0 Row count of DataFrame is: 4
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP