Python 从pandas.max()中的多个对象获取最大值

Python 从pandas.max()中的多个对象获取最大值,python,pandas,syntax-error,max,Python,Pandas,Syntax Error,Max,我有这样一个数据集: ID column_1 column_2 column_3 column 4 AAA 0.1 0.6 0.1 0.2 AAA 0.2 0.2 0.2 0.1 BBB 0.5 0.5 0.1 0.1 BBB 0.1 0.3 0.1 0.2 但它给了我一个错误: SyntaxError: invalid character in

我有这样一个数据集:

ID   column_1  column_2 column_3 column 4
AAA   0.1        0.6      0.1     0.2
AAA   0.2        0.2      0.2     0.1
BBB   0.5        0.5      0.1     0.1
BBB   0.1        0.3      0.1     0.2
但它给了我一个错误:

SyntaxError: invalid character in identifier
预期输出可描述为以下示例: 对于第一行-输出=(0.1-0.6)/max(0.1,5*0.1,0.01*abs(0.2))=-0.5/0.5=-1 有人能给我一些提示吗?提前感谢。

解决方案是通过加入它们,然后每行使用
max

s = pd.concat([df['column_3'], 
               5 * df['column_1'], 
               0.01 * abs(df['column_4'])], axis=1).max(axis=1)
output = (df['column_1'] - df['column_2']) / s
print (output)
0   -1.0
1    0.0
2    0.0
3   -0.4
dtype: float64
解决方案是通过连接它们,然后每行使用
max

s = pd.concat([df['column_3'], 
               5 * df['column_1'], 
               0.01 * abs(df['column_4'])], axis=1).max(axis=1)
output = (df['column_1'] - df['column_2']) / s
print (output)
0   -1.0
1    0.0
2    0.0
3   -0.4
dtype: float64

你的负号不是真正的负号
(df['column\u 1']–df['column\u 2'])
。你用em破折号代替en破折号。

你的负号实际上不是负号
(df['column\u 1']–df['column\u 2'])
。你用em破折号代替en破折号。

谢谢,但是你知道我的代码有什么问题吗?你的输出不正确,第一行的输出应该是-1,而不是0.5你在比较最大值时忽略了'df['column_3'],在pandasIt works中有什么方法可以使用吗?结果是关于“-”的输入错误,你是对的,谢谢你的回答@Cecilia-然后将
df['column_3']
更改为
pd.Series(1,index=df.index)
谢谢,但是您知道我的代码有什么问题吗?您的输出不正确,第一行的输出应该是-1,而不是0.5您在比较最大值时忽略了'df['column_3'],有什么方法可以在pandasIt works中使用吗,原来有一个关于“-”的拼写错误,你是对的,谢谢你的回答@塞西莉亚-然后将
df['column_3']
更改为
pd.Series(1,index=df.index)