gpt4 book ai didi

python-3.x - pandas dataframe 中这一行的输出表示什么?

转载 作者:行者123 更新时间:2023-12-04 17:21:28 26 4
gpt4 key购买 nike

我正在学习 Pandas DataFrame 并遇到了这段代码:

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6]]))

现在,当我按照 this page 上的建议使用 print(list(df.columns.values)) 时,输出为:

[0, 1, 2]

我无法理解输出。值 0,1,2 表示什么。由于 DataFrame 的高度为 2,我想最后一个值 2 表示高度。 0 和 1 呢?

如果这个问题重复,我深表歉意。我找不到任何相关的解释。如果有任何类似的问题,请提及链接。

非常感谢。

最佳答案

如果问题是什么是列检查样本:

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6]]))
print (df)
0 1 2
0 1 2 3
1 4 5 6

#default columns names
print(list(df.columns.values))
[0, 1, 2]

print(list(df.index.values))
[0, 1]

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6]]), columns=list('abc'))
print (df)
a b c
0 1 2 3
1 4 5 6

#custom columns names
print(list(df.columns.values))
['a', 'b', 'c']

print(list(df.index.values))
[0, 1]

您还可以检查docs :

The axis labeling information in pandas objects serves many purposes:

Identifies data (i.e. provides metadata) using known indicators, important for analysis, visualization, and interactive console display
Enables automatic and explicit data alignment
Allows intuitive getting and setting of subsets of the data set

关于python-3.x - pandas dataframe 中这一行的输出表示什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49461528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com