-2

I ran the following codes and I'm confused with the assignment logic. In the example, I randomly set the 1st dataframe and pulled the table. On the 2nd line of code, I tried assigning the original dataframe to the 2nd dataframe and worked with it by adding additional column. When I pulled the 1st dataframe again (df1), it's showing the added column. Can anyone assist to explain this?

Screenshot

Cmingy
  • 1
  • Welcome to StackOverflow @Cmingy! You should look [here](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) to produce reproducible problems! – Oddaspa Aug 26 '21 at 09:11
  • You should never describe code but show it. – luk2302 Aug 26 '21 at 09:17

1 Answers1

1

You just gave the same Dataframe two names with df2 = df1. Assignment never copies data. You can issue df2 = df1.copy().

timgeb
  • 76,762
  • 20
  • 123
  • 145