Absolute value for column in Python

后端 未结 1 2035
不知归路
不知归路 2020-12-01 20:55

How could I convert the values of column \'count\' to absolute value?

A summary of my dataframe this:

                


        
相关标签:
1条回答
  • 2020-12-01 21:04

    Use pandas.DataFrame.abs().

    import pandas as pd
    
    df = pd.DataFrame(data={'count':[1, -1, 2, -2, 3, -3]})
    
    df['count'] = df['count'].abs()
    
    print(df)
       count
    #0      1
    #1      1
    #2      2
    #3      2
    #4      3
    #5      3
    
    0 讨论(0)
提交回复
热议问题