Skip to content
Advertisement

Applying function to Column AttributeError: ‘int’ object has no attribute

I have a pandas data frame that consists of special/vanity numbers.

JavaScript

I would like to add a column to classify each number based on its pattern using regex.

I have written a function that iterates through the column MNM_MOBILE_NUMBER. Identifies the pattern of each number using regex. Then, creates a new column MNC_New_Class with the relevant classification.

JavaScript

Then, I wrote this line of code to apply the function to the column.

JavaScript

However, I keep getting this error

AttributeError: ‘int’ object has no attribute ‘MNM_MOBILE_NUMBER’

Any advice on how to avoid this error?

Thank you

Advertisement

Answer

When you pass a function to Pandas’ apply(), it receives the value of the selected column, not the data frame itself. So you should rewrite your code accordingly:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement