I am trying to add some constant values to a data frame.
I have successfully done multiplication, but now addition does not work.
This works:
df_C2H_TT_y1['DURATION_H'] = df_C2H_TT_y1['DURATION_H'] * 0.95
This does not work:
TT_Base = pd.DataFrame()
TT_Base["TT"] = (0.05 A2C_TT_x2['DURATION_H']) 0.25 df_C2H_TT_y1['DURATION_H'] 0.58333333333333333333333333333333)
TT_Base
Output:
5 NaN
10 NaN
23 NaN
31 NaN
44 NaN
..
637842 NaN
638152 NaN
638153 NaN
638199 NaN
638365 NaN
Name: Yes, Length: 32819, dtype: float64
What is wrong here?
CodePudding user response:
you should try df.values. Hope it should work.
TT_Base = pd.DataFrame()
TT_Base["Base_TT"] = 0.05 A2C_TT_x2['DURATION_H'].values 0.25 df_C2H_TT_y1['DURATION_H'].values 0.58333333333333333333333333333333
TT_Base
CodePudding user response:
Your code has no problem from outside. But it will only work if certain conditions are satisfied. For ex. if both all data frames on the right side are in same format, same length then there shouldn't be any errors.
But when there are operations like this, it's best to explicitly cover all conditions.
To elaborate more please post A2C_TT_x2['DURATION_H']
and df_C2H_TT_y1['DURATION_H']
etc.