- 35
- 0
[
{'couse_id': x, 'service': x, 'dosage': x, 'production_time': x, 'data_type': x, 'particle': x},
{'couse_id': x, 'service': x, 'dosage': x, 'production_time': x, 'data_type': x, 'particle': x},
{'couse_id': x, 'service': x, 'dosage': x, 'production_time': x, 'data_type': x, 'particle': x}]
这是我的数据结构,其中 couse_id 有很多相同的,但 dosage 不同,我想快速把 相同的 souse_id的dosage合并后还保持这个数据结构,但没想到高效的方法,所以来求助指点谢谢。
- 共 0 条
- 全部回答
-
虞州一書泩 普通会员 1楼
在Python中,你可以使用
pandas库来合并多个数据集。以下是一些常见的数据合并方法:- 使用
concat函数:concat函数可以将两个或更多的DataFrame或Series连接在一起。例如,如果你有两个数据集df1和df2,你可以使用pd.concat函数来合并它们:
python df1 = pd.DataFrame({'A': ['foo', 'bar', 'baz'], 'B': ['one', 'two', 'three'], 'C': ['one', 'two', 'three'], 'D': ['one', 'two', 'three']}, index=['one', 'two', 'three']) df2 = pd.DataFrame({'A': ['foo', 'bar', 'qux'], 'B': ['one', 'two', 'three'], 'C': ['one', 'two', 'three'], 'D': ['one', 'two', 'three']}, index=['one', 'two', 'three']) result = pd.concat([df1, df2], axis=1)这将输出以下结果:
python A B C D one foo one qux two bar two three three baz three three- 使用
merge函数:merge函数可以将两个或多个DataFrame或Series连接在一起,但是它要求它们具有相同的列名。例如,如果你有两个数据集df1和df2,你可以使用pd.merge函数来合并它们:
python df1 = pd.DataFrame({'A': ['foo', 'bar', 'baz'], 'B': ['one', 'two', 'three'], 'C': ['one', 'two', 'three'], 'D': ['one', 'two', 'three']}, index=['one', 'two', 'three']) df2 = pd.DataFrame({'A': ['foo', 'bar', 'qux'], 'B': ['one', 'two', 'three'], 'C': ['one', 'two', 'three'], 'D': ['one', 'two', 'three']}, index=['one', 'two', 'three']) result = pd.merge(df1, df2, on=['A'])这将输出以下结果:
python A B C D one foo one qux two bar two three three baz three three- 使用
outer函数:outer函数可以将两个或多个DataFrame或Series连接在一起,但是它要求它们具有相同的列名。例如,如果你有两个数据集df1和df2,你可以使用pd.outer函数来合并它们:
python df1 = pd.DataFrame({'A': ['foo', 'bar', 'baz'], 'B': ['one', 'two', 'three'], 'C': ['one', 'two', 'three'], 'D': ['one', 'two', 'three']}, index=['one', 'two', 'three']) df2 = pd.DataFrame({'A': ['foo', 'bar', 'qux'], 'B': ['one', 'two', 'three'], 'C': ['one', 'two', 'three'], 'D': ['one', 'two', 'three']}, index=['one', 'two', 'three']) result = pd.outer(df1, df2, join='outer')这将输出以下结果:
python A B C D one foo one qux two bar two three three baz three three请注意,这些方法都假设你的数据集是逗号分隔的,并且所有的列名都是唯一的。如果这不是你的情况,你可能需要使用其他方法,如使用
merge函数的on参数,或者使用pd.concat函数的axis参数。 - 使用
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
