cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Applying a formula to list of python dataframes produces error: object of type 'builtin_function_or_method' has no len(). How to fix?

Jack
New Contributor II

I have a df where I am calculating values by month. When I run this code on my df it generates the desired results:

for i in range(12,len(df.index)):
    df.iloc[i, 1] = df.iloc[i-12,1]*(((df.iloc[i,3]/100)+(df.iloc[i,6]/100))+1)

So far so good. I want to apply this same formula to more than 1 df so I try using a list & modify the code above. To begin I place my initial df into the list and run the code:

my_dfs=[df]
 
for i in range(12,len(my_dfs.index)):
    my_dfs.iloc[i, 1] = my_dfs.iloc[i-12,1]*(((my_dfs.iloc[i,3]/100)+(my_dfs.iloc[i,6]/100))+1)

But I get the error message:

object of type 'builtin_function_or_method' has no len()

How do I fix this?

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @Jack Homareau​ , First, check if

my_dfs.index

returns something. Then try applying len() over it.

The function does not have a length, so calling len with a function as the argument does not make sense.

Anonymous
Not applicable

Hey there @Jack Homareau​ 

Hope all is well!

Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.