Skip to main content
Solved

setting new attributes

  • February 3, 2020
  • 7 replies
  • 163 views

Hi there,

 

I am calculating two new fields in Python caller. When I tried to set those attributes, I got an error message of "Python Exception <TypeError>: Could not convert attribute value to a supported attribute type." Here is the part of my code:

self.df2['Normalized_SAIDI_DPP2'] = self.df2['SAIDI'].apply(self.normalized_SAIDI) self.df2['Normalized_SAIFI_DPP2'] = self.df2['SAIFI'].apply(self.normalized_SAIFI)

newFeature = fmeobjects.FMEFeature()

newFeature.setAttribute('Normalized_SAIDI_DPP2',self.df2['Normalized_SAIDI_DPP2'])

Datatype of self.df2['Normalized_SAIDI_DPP2'] is string. I got an error message on the last line. Could anyone guide me where am I making the mistake?

 

Best answer by debbiatsafe

Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.

View original
Did this help you find an answer to your question?

7 replies

Forum|alt.badge.img
  • February 4, 2020

I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.


davidrich wrote:

I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.

Sorry I forgot to mentioned that I also converted the object into string but didn't work. My code was self.df2. Normalized_SAIDI_DPP2'. astype(str).


davidrich wrote:

I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.

This is my updated code but still throwing the same error message:

newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('Normalized_SAIDI_DPP2',self.df2['Normalized_SAIDI_DPP2'].astype(str))


davidrich wrote:

I don't think self.df2['Normalized_SAIDI_DPP2'] would be a string as I am guess that you are using pandas dataframe and using .apply with returns a Series or DataFrame so therefore you will need to convert this to string.

I have also tested the following code but ended with same error

newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('Normalized_SAIDI_DPP2',pd.to_numeric(self.df2['Normalized_SAIDI_DPP2']))

Error is :

Python Exception <TypeError>: Could not convert attribute value to a supported attribute type.

Traceback (most recent call last):

File "<string>", line 63, in close

TypeError: Could not convert attribute value to a supported attribute type.

NORMALIZED_DPP2 (PythonFactory): PythonFactory failed to close properly

NORMALIZED_DPP2 (PythonFactory): A fatal error has occurred. Check the logfile above for details


debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • February 12, 2020

Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.


debbiatsafe wrote:

Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.

Yes, you are right, result is <class 'pandas.core.series.Series'> . What does that mean? Could you please also explain what do you mean by use of for loop to access the data values?


debbiatsafe wrote:

Hi @muhammad_yasir

I'll preface this by saying I'm not familiar with the pandas module at all.

Based on the Pandas documentation, the astype Pandas method only converts Pandas objects (the data values in the column) to the data type specified. You can verify this by using the following Python to check the type:

print(type(self.df2['Normalized_SAIDI_DPP2'].astype(str)))

The results will likely be <class 'pandas.core.series.Series'>. This is not a supported data type as the error returned from the PythonCaller indicates.

 

Perhaps you can use a for loop to access the data values within the Series object.

Do you mean something like this......

for i in self.df2['Normalized_SAIDI_DPP2']:

            newFeature = fmeobjects.FMEFeature()

            newFeature.setAttribute('Normalized_SAIDI_DPP2',i)  

            self.pyoutput(newFeature)

 

        pass


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