python - Pandas:创建带有条件的新列
问题描述
我是熊猫新手,我做了一些分析练习。我想创建一个新列,其值是两列的乘积,条件是: 通过乘以典型价格 * 交易量来计算资金流量,如果一天的“典型价格”大于“典型价格”,该值将为正'前一天的。否则,该值将为负数。按照此规则,第一行将没有“资金流”值,因为它无法与前一天进行比较。
原始数据集如下:
Volume Typical Price
3509 47.810000
4862 48.406667
1810 49.260000
3824 49.263333
2209 47.386667
4558 45.573333
3832 44.396667
3778 43.750000
1005 44.640000
4047 43.760000
2201 44.383333
2507 45.156667
预期结果是有新列 Money Flow Positive 和 Negative。
Volume Typical Price Money Flow Positive Money Flow Negative
3509 47.810000
4862 48.406667
1810 49.260000
3824 49.263333
2209 47.386667
4558 45.573333
3832 44.396667
3778 43.750000
1005 44.640000
4047 43.760000
2201 44.383333
2507 45.156667
我想到的逻辑是……
if Money flow negative than previous Money flow move to Money Flow negative
if Money flow positive than previous Money flow move to Money Flow positive
我不太确定如何在具有上述条件的熊猫中创建 if 语句,有什么建议吗?
解决方案
推荐阅读
- wordpress - 图片未显示在本地主机上
- c# - 如何从列表中打印 1 列
- swift - UITextField 在动画开始时缩小文本
- android - Crashlytics 未报告应用程序包崩溃但使用 apk 工作正常
- java - Tomcat 使用了一个不存在的 JRE_HOME
- android - 根据之前 API 调用的结果进行 RxJava 调用的最佳方式
- python - args 没有定义?
- serialization - 类序列化在nestjs中不起作用
- ruby - Ruby regexp 中的简单重复不起作用
- intel - 如何通过 FPGA 板安装修复“找不到 board_env.xml”