【发布时间】:2017-03-30 07:37:10
【问题描述】:
我必须考虑数据框的两个不同列的值。用乘法和除法计算它们,并将结果放在新列中。我写了这个,但它不起作用:
for x in range(len(df1)):
if df1.iloc[x,4] is not 'NaN':
number1=float(df1.iloc[x,4])
if df1.iloc[x,8] is not 'NaN':
number2=float(df1.iloc[x,8])
total=((number1*number2)/100)
df1['total number']=total
df1.head()
这是我的输出:
number1 number2 total number
0 400 90 100,0
1 35,5 50 100,0
2 678 3,4 100,0
相反,我想要这样的输出:
number1 number2 total number
0 400 90 40,5
1 35,5 50 17,75
2 678 3,4 23,05
【问题讨论】:
-
可以添加输入吗?
-
对不起,我不明白。您建议将结果添加为输入?
-
对不起,
but it doesn't work是什么意思?数据中有一些NaN吗?如果是,期望的输出是什么?
标签: python database python-2.7 pandas dataframe