Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:找到最大值_Python_Pandas_Series - Fatal编程技术网

Python:找到最大值

Python:找到最大值,python,pandas,series,Python,Pandas,Series,我有一个系列 reg_s_lag Out[71]: X1 1.0 X2 1.0 X3 13.0 X4 13.0 X5 16.0 X6 2.0 X7 16.0 X8 16.0 X9 16.0 X10 2.0 Name: max_pos_arg, dtype: f

我有一个系列

reg_s_lag
Out[71]: 
X1             1.0
X2             1.0
X3             13.0
X4             13.0
X5             16.0
X6             2.0
X7             16.0
X8             16.0
X9             16.0
X10            2.0
Name: max_pos_arg, dtype: float64
我想要一个新的数列,这样所有的值都以2.0为下限。也就是说,将X1和X2转换为2.0,同时保持所有其他元素不变。我该怎么做? 这不起作用:

max(reg_s_lag, 2)

以下代码将替换所有小于阈值的值:

import pandas as pd

data = {
    "X1": 1.0,
    "X2": 1.0,
    "X3": 13.0,
    "X4": 13.0,
    "X5": 16.0,
    "X6": 2.0,
    "X7": 16.0,
    "X8": 16.0,
    "X9": 16.0,
    "X10": 2.0
}

threshold = 2.0
reg_s_lag = pd.Series(data)
reg_s_lag[reg_s_lag<threshold] = threshold
print(reg_s_lag)

这里我使用了
threshold=2.0

Hi,is
2.0
是常量值吗[df@DavidDr902.0是一个常数。有很多方法,
df[df=2否则2.0)
。注意前两个更改原始
df
最后一个解决方案返回一个新的
df
,带有所需值。
X1      2.0
X2      2.0
X3     13.0
X4     13.0
X5     16.0
X6      2.0
X7     16.0
X8     16.0
X9     16.0
X10     2.0
dtype: float64