Skip to main content
Question

Defining dataframe at Python Caller

  • January 29, 2020
  • 2 replies
  • 79 views

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?

 

 

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • 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
  • 9 replies
  • August 11, 2020

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