Skip to content
Advertisement

Binding a dataframe to a variable in a for-loop converts it into a tuple?

Sorry if this is basic but I am new to python.

I was experimenting with creating plots in pandas through a for loop when I got AttributeError: 'tuple' object has no attribute 'plot'.

Looking at my code, I found out that assigning a dataframe to a variable converts it into a tuple. See below:

JavaScript

Output:

JavaScript

This doesn’t happen if I do the same thing outside the for-loop.

JavaScript

Output:

JavaScript

Can someone explain to me python’s assignment logic here? Why is this happening?

Advertisement

Answer

In the for loop,

JavaScript

you add an extra comma , at the end, and that results:

JavaScript

tuple defination:

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