Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'DataFrame' object has no attribute 'iteritems' [duplicate]

I am using pandas to read csv on my machine then I create a pyspark dataframe from pandas dataframe.

df = spark.createDataFrame(pandas_df) 

I updated my pandas from version 1.3.0 to 2.0

Now, I am getting this error:

enter image description here


enter image description here

AttributeError: 'DataFrame' object has no attribute 'iteritems'
like image 435
Talha Tayyab Avatar asked Apr 13 '26 17:04

Talha Tayyab


1 Answers

Found an answer on github: https://github.com/YosefLab/Compass/issues/92

It is an issue going on.

iteritems is removed from pandas 2.0

For now I need to downgrade pandas back to version 1.5.3


Edit:

Other workarounds may be

Use the latest Spark (3.4.1)

https://spark.apache.org/downloads.html


For pandas >=2.0

You can also assign DataFrame.items to DataFrame.iteritems

import pandas as pd
pd.DataFrame.iteritems = pd.DataFrame.items

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.items.html?highlight=items#pandas.DataFrame.items

like image 179
Talha Tayyab Avatar answered Apr 16 '26 06:04

Talha Tayyab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!