如何在python代码中实现R的case-when函数?在
当R的函数为:
https://www.rdocumentation.org/packages/dplyr/versions/0.7.8/topics/case_when
作为最低限度的工作示例,假设我们有以下数据帧(python代码如下所示):
import pandas as pd
import numpy as np
data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'age': [42, 52, 36, 24, 73],
'preTestScore': [4, 24, 31, 2, 3],
'postTestScore': [25, 94, 57, 62, 70]}
df = pd.DataFrame(data, columns = ['name', 'age', 'preTestScore', 'postTestScore'])
df
假设我们要创建一个名为“老年人”的新列,该列查看“年龄”列并执行以下操作:
^{pr2}$有人能帮忙吗?在
您要使用^{} :
conditions
和{相关问题 更多 >
编程相关推荐