Skip to main content
Question

Defining dataframe at Python Caller


Hi there,

 

I am defining a data frame at Python caller on __init__ function like below:

 

class FeatureProcessor(object):

def __init__(self):

df2 = pandas.DataFrame(columns= ['INCIDENT_DATE',INCIDENT_MINS','INCIDENT_VALUE'])

later in the program at input function I am storing feature attribute value in data frame something like that:

def input(self,feature):

self.pyoutput(feature)

df2['INCIDENT_DATE'] = feature.getAttribute('DATE')

df2['INCIDENT_MINS'] = feature.getAttribute('MINS')

df2['INCIDENT_VALUE'] = feature.getAttribute('VALUE_LOST')

 

However, when I ran the Python caller block, it throws an error message that df2 is not defined at the input block. Could anyone point out where am I making the mistake?

 

 

 

 

2 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • January 29, 2020

Hi @muhammad_yasir,

Objects you want to use in multiple methods should be prefixed with 'self.'

ie.

self.df2 = pandas.DataFrame....

.

.

self.df2['INCIDENT_DATE'] =

 


jseigneuret

Hum. 

you create a feature output with same value input. 

def input(self,feature):
    self.pyoutput(feature)

  and df2 dataframe can't be set in the constructor __init__ . 

Create a method class to populate data and manipulate it add set your self.df attribute

at the end call a method to generate all your features

def close(self):
    exposeDf(self.df)

in exposeDf method you need create 1 by 1 all element in your df to create all features

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings