>> df1 = pd.DataFrame({"x":[1, 2, 3, 4, 5], "y":[3, 4, 5, 6, 7]}, -6ren">
gpt4 book ai didi

python - Pandas DataFrame 中的 "axis"属性是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 20:44:06 26 4
gpt4 key购买 nike

举个例子:

>>> df1 = pd.DataFrame({"x":[1, 2, 3, 4, 5], 
"y":[3, 4, 5, 6, 7]},
index=['a', 'b', 'c', 'd', 'e'])

>>> df2 = pd.DataFrame({"y":[1, 3, 5, 7, 9],
"z":[9, 8, 7, 6, 5]},
index=['b', 'c', 'd', 'e', 'f'])

>>> pd.concat([df1, df2], join='inner')

输出是:

   y
a 3
b 4
c 5
d 6
e 7
b 1
c 3
d 5
e 7
f 9

由于 axis=0 是列,我认为 concat() 只考虑在两个数据帧中找到的 columns。但是实际输出会考虑在两个数据帧中都可以找到的

axis参数的具体含义是什么?

最佳答案

如果有人需要视觉描述,这里是图片:

Axis 0 or 1 in Pandas Python

关于python - Pandas DataFrame 中的 "axis"属性是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39283339/

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