Home > Blockchain >  Feature engineering, key error in python?
Feature engineering, key error in python?

Time:10-25

I am currently creating some additional features for my ML project. I created one feature (f1), insert it as a new column and want to use it now to calculate another feature, but I get a KeyError.

df['f1'] = df['column1'] - df['column2'] -->works fine

f1 has dtype: timedelta64, e.g. '0 days', '43 days'. Then I want to use this new column.

df['f2'] = df['f1']   df ['column3'] --> Error occurs 

Errors:

KeyError Traceback (Most recent call last)
KeyError 'f1'

I don't know, what I can change to make it work. Thank you so much in advance.

CodePudding user response:

Like the order you have written should works, if it gives error that f1 keys does not exist, maybe you are runing these lines in a notebook, and you are executing the second line before f1 created (like first line)

  • Related