Python Forum
Using .append() with list vs dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using .append() with list vs dataframe
#7
(Jun-11-2022, 10:07 PM)deanhystad Wrote: Python objects live only as long as they are referenced. Unreferenced objects get garbage collected and their memory is reused to make new objects. color = "blue" assigns a str object to a variable named "color". Right now there is only one reference to the str object "blue". If I do this, color = 1, the variable color now references an int object. Now the str object "blue" is not referenced by any variables. It's reference count is zero. There is no way for me to use the str object "blue" anymore because I don't have any variables that reference it. In many languages "blue" would continue to exist in limbo, taking up space until the program ends. In Python, assigning color = 1 not only assigns color to reference an int object, it unassigns color to stop referencing the "blue" object. The "blue" object reference count drops to zero, and Python puts it in the garbage collector.

In your example where you do this: df = df.append([['grey',12]]), the variable "df" is reassigned to reference the new dataframe object created by the append() function. The original dataframe object is no longer referenced by any variables, so it gets garbage collected.

Is that clear?

That's good stuff. So the answer to my question about where the new dataframe object goes if not assigned is that it disappears into the recycle bin. Thanks!
Reply


Messages In This Thread
Using .append() with list vs dataframe - by Mark17 - Jun-10-2022, 08:04 PM
RE: Using .append() with list vs dataframe - by Mark17 - Jun-12-2022, 06:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 756 Mar-14-2024, 06:26 PM
Last Post: flash77
Question How to append integers from file to list? Milan 8 1,652 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  function returns dataframe as list harum 2 1,584 Aug-13-2022, 08:27 PM
Last Post: rob101
  read a text file, find all integers, append to list oldtrafford 12 4,031 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  List of dataframe values beginning with x,y or z glidecode 3 2,033 Nov-08-2021, 10:16 PM
Last Post: glidecode
  Reading data to python: turn into list or dataframe hhchenfx 2 5,567 Jun-01-2021, 10:28 AM
Last Post: Larz60+
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,435 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Add a row to a dataframe or append whole dataframe. tsurubaso 1 1,543 Jan-07-2021, 01:53 AM
Last Post: tsurubaso
  convert list to five columns dataframe in sequence tonycat 2 2,586 Sep-29-2020, 06:47 AM
Last Post: tonycat
  How to append to list a function output? rama27 5 6,958 Aug-24-2020, 10:53 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020