给出以下数据:
data = {'type': ['chisel', 'disc', 'user_defined'],
'depth': [[152, 178, 203], [127, 152, 178, 203], [0]],
'residue': [[0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], [0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], [0.0]],
'timing': [["10-nov", "10-apr"], ["10-nov", "10-apr"], ["10-apr"]]}
创建df
:
^{pr2}$
按预期输出:
explode
timing
:
df = df.explode('timing')
按预期输出:
explode
depth
:
df = df.explode('depth')
输出不符合预期:
- 我希望
chisel
有6行,8行disc
- 每个3个,用于
10-apr
&;10-nov
,用于chisel
- 每个4个,用于
10-apr
&;10-nov
,用于disc
explode
的产量是预期的两倍
- 12而不是6,对于
chisel
- 16而不是8,对于
disc
问题:
- 我的期望不正确吗?在
- 我是不是用错了
explode
?在
Tags:
无论何时使用重复索引,
pandas
都会产生意外的结果。请注意,在第一个explode
之后,您将得到重复的索引。在重置它们将产生一个如您所期望的那样工作的数据帧。在
用
^{pr2}$
相关问题 更多 >
编程相关推荐