[英]pandas: subtracting two columns and saving result as an absolute
I have the code where I have a csv file opened in pandas and a new one I'm creating. 我有代码,我在pandas中打开了一个csv文件,我正在创建一个新的。 There's a row I need to create "two last lines commented out" of an absolute value of subtracting two rows.
有一行我需要创建一个“减去两行的绝对值”的“最后两行注释掉”。 I've tried a number of ideas in my head all bring an error.
我在脑海里尝试了很多想法都带来了错误。
import pandas as pd
import numpy as np
df = pd.read_csv(filename_read)
ids = df['id']
oosDF = pd.DataFrame()
oosDF['id'] = ids
oosDF['pred'] = pred
oosDF['y'] = df['target']
#oosDF['diff'] = oosdF['pred'] - oosDF['y']
#oosDF['diff'] = oosDF.abs()
In your first commented line, you have oosdF
instead of oosDF
. 在您的第一个注释行中,您有
oosdF
而不是oosDF
。
In your second commented line, you're setting the column to be abs()
applied to the whole dataframe. 在第二个注释行中,您将列设置为
abs()
应用于整个数据帧。 That should be oosDF['diff'].abs()
那应该是
oosDF['diff'].abs()
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.