Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is a copy and paste line from a data science experiment I am trying to run.

for col,num in zip(df.toPandas().describe().columns(),range(1,11)):

It shows output but not on Databricks.

Error is:

TypeError: 'Index' object is not callable

Any ideas?

question from:https://stackoverflow.com/questions/65600924/pyspark-index-object-is-not-callable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
231 views
Welcome To Ask or Share your Answers For Others

1 Answer

As the error says, you can't call an index object, which is df.toPandas().describe().columns. Try removing the brackets:

for (col, num) in zip(df.toPandas().describe().columns, range(1,11)):

perhaps a better way is to use enumerate instead of zip, which avoids the need to hard code the number of columns:

for (num, col) in enumerate(df.toPandas().describe().columns):

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...