【发布时间】:2015-01-18 10:33:20
【问题描述】:
我有一个看起来像这样的熊猫数据框:
portion used
0 1 1.0
1 2 0.3
2 3 0.0
3 4 0.8
我想基于used 列创建一个新列,使df 看起来像这样:
portion used alert
0 1 1.0 Full
1 2 0.3 Partial
2 3 0.0 Empty
3 4 0.8 Partial
- 创建一个新的
alert列基于 - 如果
used是1.0,则alert应该是Full。 - 如果
used是0.0,则alert应该是Empty。 - 否则,
alert应该是Partial。
最好的方法是什么?
【问题讨论】:
标签: python pandas conditional calculated-columns