0

I've created a pandas DataFrame with data from loops (data saved here). Now, I want to iterate over this DataFrame. However, when I try to access the items() function like this:

frame = pandas.read_csv(data_path + '/file1.csv')
frame.items()

I get this error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\ArcGIS10.7\lib\site-packages\pandas\core\generic.py", line 2668, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'items'

This is especially weird since PyCharm offers me the option to fill in items if I just type frame.it
What does this mean?

Florian Mlehliv
  • 133
  • 1
  • 6
  • use [`dataframe.iterrows()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iterrows.html#pandas.DataFrame.iterrows) – anurag Jan 19 '21 at 09:20
  • For me working well. – jezrael Jan 19 '21 at 09:21
  • 1
    Does this answer your question: https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas – anurag Jan 19 '21 at 09:21
  • the `DataFrame` object has no function called `items` if you want to go through the rows you need to use `iterrows()`. – nidabdella Jan 19 '21 at 09:22
  • Thanks! I guess I will use iterrows() and just look at one column. Still weird why there is not items attribute... – Florian Mlehliv Jan 19 '21 at 09:27
  • @nidabdella we do have [`dataframe.items()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.items.html#pandas.DataFrame.items) though! – anurag Jan 19 '21 at 09:28

1 Answers1

0

Check your pycharm interpreter. Normally the attribute 'items' works well in Python 3.x but gives the error "AttributeError: 'DataFrame' object has no attribute 'items'" in Python 2.7.

I also faced the same error until I realized that I was using Python 2.7 instead of Python 3.9 that I intended to use.

Zivo
  • 1
  • 1