如何知道一个 Python DataFrame 有多少行内容?可以使用 'shape' 属性来获取 DataFrame 的行数和列数。例如:

import pandas as pd

data = {'col1': [1, 2, 3, 4, 5],
        'col2': [6, 7, 8, 9, 10],
        'col3': [11, 12, 13, 14, 15]}
df = pd.DataFrame(data)

num_rows = df.shape[0]
print('Number of rows:', num_rows)

输出:

Number of rows: 5

在这个例子中,DataFrame 'df' 有 5 行数据。

Python DataFrame 行数获取:使用 shape 属性

原文地址: https://www.cveoy.top/t/topic/lU7a 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录