pandas concat 左右拼接 ignore_index 容易误以为是忽略index 其实是忽略列名
  X5zJxoD00Cah 2023年12月06日 21 0

pandas concat 左右拼接 ignore_index 容易误以为是忽略index 其实是忽略列名

pandas concat 左右拼接 ignore_index 容易误以为是忽略index 其实是忽略列名_.net


`pandas.concat` 函数的 `ignore_index` 参数是一个布尔值,用于控制是否在拼接轴上使用索引值¹²。如果 `ignore_index=True`,则不会使用拼接轴上的索引值,结果轴将被标记为 0, …, n - 1¹²。这在你拼接的对象在拼接轴上没有有意义的索引信息时非常有用¹²。注意,其他轴上的索引值在连接时仍然会被尊重¹²。


以下是一个示例¹²:


```python

import pandas as pd


# 创建两个 Series

s1 = pd.Series(['a', 'b'])

s2 = pd.Series(['c', 'd'])


# 使用 `concat` 函数和 `ignore_index` 参数将两个 Series 拼接

result = pd.concat([s1, s2], ignore_index=True)


print(result)

```


这将输出:


```

0    a

1    b

2    c

3    d

dtype: object

```


在这个例子中,`pd.concat([s1, s2], ignore_index=True)` 将两个 Series 对象 `s1` 和 `s2` 拼接,并且设置 `ignore_index=True` 使得结果的索引是从 0 到 n - 1 的整数¹²。希望这些信息对你有所帮助!


源: 与必应的对话, 2023/12/4

(1) pandas.concat — pandas 2.1.3 documentation. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.concat.html.

(2) pandas中 concat 的使用_pd.concat ignore_index_种麦南山下的博客-CSDN博客. https://blog.csdn.net/conving/article/details/120195417.

(3) Pandas系列(十一)Pandas中concat合并两个dataframe - CSDN博客. https://blog.csdn.net/weixin_39059031/article/details/108021392.

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月06日 0

暂无评论

推荐阅读
  X5zJxoD00Cah   2023年12月11日   15   0   0 知乎Python迭代器
  X5zJxoD00Cah   2023年12月12日   17   0   0 Python.net
X5zJxoD00Cah