Python 如何使用pandas将列中的值更改为正值,并将舍入更改为单个小数点

Python 如何使用pandas将列中的值更改为正值,并将舍入更改为单个小数点,python,pandas,numpy,Python,Pandas,Numpy,到 您可以使用abs内部的圆形功能来执行此操作: strain Standardforce stress percentage 1 10.400000 24400.0 2.750646 20.8 2 10.400000 24200.0 2.728100 20.8 3 10.400000 24100.0 2.716826 23.8 4 10.400000 23900.0


您可以使用abs内部的圆形功能来执行此操作:

    strain   Standardforce   stress    percentage
1   10.400000   24400.0     2.750646        20.8
2   10.400000   24200.0     2.728100        20.8
3   10.400000   24100.0     2.716826        23.8
4   10.400000   23900.0     2.694280        20.8

df['percentage']=df.percentage.abs().round(1)
    strain   Standardforce   stress    percentage
1   10.400000   24400.0     2.750646        20.8
2   10.400000   24200.0     2.728100        20.8
3   10.400000   24100.0     2.716826        23.8
4   10.400000   23900.0     2.694280        20.8
>>> df.percentage = df.percentage.apply(lambda x: abs(round(x, 2)))
>>> df
   strain  Standardforce    stress  percentage
1    10.4        24400.0  2.750646        20.8
2    10.4        24200.0  2.728100        20.8
3    10.4        24100.0  2.716826        23.8
4    10.4        23900.0  2.694280        20.8