我的代码返回错误:Series的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。我无法确定,也许我的代码有问题。
import numpy as np
import pandas as pd
from numpy.random import randn
np.random.seed(101)
df = pd.DataFrame(randn(5,1), columns=['col1'])
df['col2'] = 0
def nome():
ref = df['col1']
desc = df['col2']
if desc == 0:
if (ref >0.3) and (ref <=0.5):
return 'fraco'
elif (ref >0.5) and (ref <=0.7):
return 'moderado'
elif (ref >0.7) and (ref <=0.9):
return 'forte'
elif (ref >0.9):
return 'muito forte'
return desc
nome()
我需要基于'col1'进行排序,并根据功能对字符串进行排序,从而创建'col2'。
你能帮我吗?