Python中列的绝对值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29077188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:03:23 来源:igfitidea点击:
Absolute value for column in Python
提问by Yari
How could I convert the values of column 'count' to absolute value?
如何将“计数”列的值转换为绝对值?
A summary of my dataframe this:
我的数据框摘要:
datetime count
0 2011-01-20 00:00:00 14.565996
1 2011-01-20 01:00:00 10.204177
2 2011-01-20 02:00:00 -1.261569
3 2011-01-20 03:00:00 1.938322
4 2011-01-20 04:00:00 1.938322
5 2011-01-20 05:00:00 -5.963259
6 2011-01-20 06:00:00 73.711525
采纳答案by Ffisegydd
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