Deepcopy pandas DataFrame containing python objects (such as lists)2019 Community Moderator ElectionHow to deep copy Pandas Dataframe which contains nested data structure?Add one row to pandas DataFrameSelecting multiple columns in a pandas dataframeAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersCopying and Modifying a Dataframe PandasPython DataFrame particular columns conversion

Why is a white electrical wire connected to 2 black wires?

Why do tuner card drivers fail to build after kernel update to 4.4.0-143-generic?

New passport but visa is in old (lost) passport

How are passwords stolen from companies if they only store hashes?

This word with a lot of past tenses

How do you talk to someone whose loved one is dying?

Happy pi day, everyone!

What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?

Brexit - No Deal Rejection

I got the following comment from a reputed math journal. What does it mean?

ERC721: How to get the owned tokens of an address

Tikz picture of two mathematical functions

How to make healing in an exploration game interesting

What is the Japanese sound word for the clinking of money?

Why do passenger jet manufacturers design their planes with stall prevention systems?

What did “the good wine” (τὸν καλὸν οἶνον) mean in John 2:10?

How could an airship be repaired midflight?

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?

Have the tides ever turned twice on any open problem?

Counting models satisfying a boolean formula

If I am holding an item before I cast Blink, will it move with me through the Ethereal Plane?

Did Ender ever learn that he killed Stilson and/or Bonzo?

My adviser wants to be the first author

How difficult is it to simply disable/disengage the MCAS on Boeing 737 Max 8 & 9 Aircraft?



Deepcopy pandas DataFrame containing python objects (such as lists)



2019 Community Moderator ElectionHow to deep copy Pandas Dataframe which contains nested data structure?Add one row to pandas DataFrameSelecting multiple columns in a pandas dataframeAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrame by column name“Large data” work flows using pandasHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersCopying and Modifying a Dataframe PandasPython DataFrame particular columns conversion










2















Need help understanding variable assignment, pointers, ...



The following is reproducible.



import pandas as pd

df = pd.DataFrame(
'listData': [
['c', 'f', 'd', 'a', 'e', 'b'],
[5, 2, 1, 4, 3]
])

df['listDataSort'] = df['listData']


gives:



 listData listDataSort
0 [c, f, d, a, e, b] [c, f, d, a, e, b]
1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]


If I only want to sort the lists in the listDataSort column, I might try:



df['listDataSort'].apply(lambda l: l.sort())
df


However, that sorts the lists in both columns, in-place.



 listData listDataSort
0 [a, b, c, d, e, f] [a, b, c, d, e, f]
1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


I can fix this by instead doing:



df = pd.DataFrame(
'listData': [
['c', 'f', 'd', 'a', 'e', 'b'],
[5, 2, 1, 4, 3]
])

df['listDataSort'] = df['listData'].apply(sorted)


giving:



 listData listDataSort
0 [c, f, d, a, e, b] [a, b, c, d, e, f]
1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]


Assigning df to a different variable, say df2 still changes everything back to the original source list. Furthermore, how do I create a new dataframe based on an existing dataframe so I can make changes to the new dataframe without making the same changes to the existing dataframe?



df = pd.DataFrame(
'listData': [
['c', 'f', 'd', 'a', 'e', 'b'],
[5, 2, 1, 4, 3]
])

df2 = df
print('ndfn', df)
print('ndf2n', df2)

df2['listDataSort'] = df2['listData']
print('ndfn', df)
print('ndf2n', df2)

df2['listDataSort'].apply(lambda l: l.sort())
print('ndfn', df)
print('ndf2n', df2)


prints:



df
listData
0 [c, f, d, a, e, b]
1 [5, 2, 1, 4, 3]

df2
listData
0 [c, f, d, a, e, b]
1 [5, 2, 1, 4, 3]

df
listData listDataSort
0 [c, f, d, a, e, b] [c, f, d, a, e, b]
1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

df2
listData listDataSort
0 [c, f, d, a, e, b] [c, f, d, a, e, b]
1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

df
listData listDataSort
0 [a, b, c, d, e, f] [a, b, c, d, e, f]
1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]

df2
listData listDataSort
0 [a, b, c, d, e, f] [a, b, c, d, e, f]
1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


also:



df = pd.DataFrame(
'listData': [
['c', 'f', 'd', 'a', 'e', 'b'],
[5, 2, 1, 4, 3]
])
print('ndfn', df)

df3 = df
df3['listDataSort'] = df3['listData'].apply(sorted)
print('ndfn', df)
print('ndf3n', df3)


prints:



df
listData
0 [c, f, d, a, e, b]
1 [5, 2, 1, 4, 3]

df
listData listDataSort
0 [c, f, d, a, e, b] [a, b, c, d, e, f]
1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]

df3
listData listDataSort
0 [c, f, d, a, e, b] [a, b, c, d, e, f]
1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]









share|improve this question




























    2















    Need help understanding variable assignment, pointers, ...



    The following is reproducible.



    import pandas as pd

    df = pd.DataFrame(
    'listData': [
    ['c', 'f', 'd', 'a', 'e', 'b'],
    [5, 2, 1, 4, 3]
    ])

    df['listDataSort'] = df['listData']


    gives:



     listData listDataSort
    0 [c, f, d, a, e, b] [c, f, d, a, e, b]
    1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]


    If I only want to sort the lists in the listDataSort column, I might try:



    df['listDataSort'].apply(lambda l: l.sort())
    df


    However, that sorts the lists in both columns, in-place.



     listData listDataSort
    0 [a, b, c, d, e, f] [a, b, c, d, e, f]
    1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


    I can fix this by instead doing:



    df = pd.DataFrame(
    'listData': [
    ['c', 'f', 'd', 'a', 'e', 'b'],
    [5, 2, 1, 4, 3]
    ])

    df['listDataSort'] = df['listData'].apply(sorted)


    giving:



     listData listDataSort
    0 [c, f, d, a, e, b] [a, b, c, d, e, f]
    1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]


    Assigning df to a different variable, say df2 still changes everything back to the original source list. Furthermore, how do I create a new dataframe based on an existing dataframe so I can make changes to the new dataframe without making the same changes to the existing dataframe?



    df = pd.DataFrame(
    'listData': [
    ['c', 'f', 'd', 'a', 'e', 'b'],
    [5, 2, 1, 4, 3]
    ])

    df2 = df
    print('ndfn', df)
    print('ndf2n', df2)

    df2['listDataSort'] = df2['listData']
    print('ndfn', df)
    print('ndf2n', df2)

    df2['listDataSort'].apply(lambda l: l.sort())
    print('ndfn', df)
    print('ndf2n', df2)


    prints:



    df
    listData
    0 [c, f, d, a, e, b]
    1 [5, 2, 1, 4, 3]

    df2
    listData
    0 [c, f, d, a, e, b]
    1 [5, 2, 1, 4, 3]

    df
    listData listDataSort
    0 [c, f, d, a, e, b] [c, f, d, a, e, b]
    1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

    df2
    listData listDataSort
    0 [c, f, d, a, e, b] [c, f, d, a, e, b]
    1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

    df
    listData listDataSort
    0 [a, b, c, d, e, f] [a, b, c, d, e, f]
    1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]

    df2
    listData listDataSort
    0 [a, b, c, d, e, f] [a, b, c, d, e, f]
    1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


    also:



    df = pd.DataFrame(
    'listData': [
    ['c', 'f', 'd', 'a', 'e', 'b'],
    [5, 2, 1, 4, 3]
    ])
    print('ndfn', df)

    df3 = df
    df3['listDataSort'] = df3['listData'].apply(sorted)
    print('ndfn', df)
    print('ndf3n', df3)


    prints:



    df
    listData
    0 [c, f, d, a, e, b]
    1 [5, 2, 1, 4, 3]

    df
    listData listDataSort
    0 [c, f, d, a, e, b] [a, b, c, d, e, f]
    1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]

    df3
    listData listDataSort
    0 [c, f, d, a, e, b] [a, b, c, d, e, f]
    1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]









    share|improve this question


























      2












      2








      2








      Need help understanding variable assignment, pointers, ...



      The following is reproducible.



      import pandas as pd

      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])

      df['listDataSort'] = df['listData']


      gives:



       listData listDataSort
      0 [c, f, d, a, e, b] [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]


      If I only want to sort the lists in the listDataSort column, I might try:



      df['listDataSort'].apply(lambda l: l.sort())
      df


      However, that sorts the lists in both columns, in-place.



       listData listDataSort
      0 [a, b, c, d, e, f] [a, b, c, d, e, f]
      1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


      I can fix this by instead doing:



      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])

      df['listDataSort'] = df['listData'].apply(sorted)


      giving:



       listData listDataSort
      0 [c, f, d, a, e, b] [a, b, c, d, e, f]
      1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]


      Assigning df to a different variable, say df2 still changes everything back to the original source list. Furthermore, how do I create a new dataframe based on an existing dataframe so I can make changes to the new dataframe without making the same changes to the existing dataframe?



      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])

      df2 = df
      print('ndfn', df)
      print('ndf2n', df2)

      df2['listDataSort'] = df2['listData']
      print('ndfn', df)
      print('ndf2n', df2)

      df2['listDataSort'].apply(lambda l: l.sort())
      print('ndfn', df)
      print('ndf2n', df2)


      prints:



      df
      listData
      0 [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3]

      df2
      listData
      0 [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3]

      df
      listData listDataSort
      0 [c, f, d, a, e, b] [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

      df2
      listData listDataSort
      0 [c, f, d, a, e, b] [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

      df
      listData listDataSort
      0 [a, b, c, d, e, f] [a, b, c, d, e, f]
      1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]

      df2
      listData listDataSort
      0 [a, b, c, d, e, f] [a, b, c, d, e, f]
      1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


      also:



      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])
      print('ndfn', df)

      df3 = df
      df3['listDataSort'] = df3['listData'].apply(sorted)
      print('ndfn', df)
      print('ndf3n', df3)


      prints:



      df
      listData
      0 [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3]

      df
      listData listDataSort
      0 [c, f, d, a, e, b] [a, b, c, d, e, f]
      1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]

      df3
      listData listDataSort
      0 [c, f, d, a, e, b] [a, b, c, d, e, f]
      1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]









      share|improve this question
















      Need help understanding variable assignment, pointers, ...



      The following is reproducible.



      import pandas as pd

      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])

      df['listDataSort'] = df['listData']


      gives:



       listData listDataSort
      0 [c, f, d, a, e, b] [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]


      If I only want to sort the lists in the listDataSort column, I might try:



      df['listDataSort'].apply(lambda l: l.sort())
      df


      However, that sorts the lists in both columns, in-place.



       listData listDataSort
      0 [a, b, c, d, e, f] [a, b, c, d, e, f]
      1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


      I can fix this by instead doing:



      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])

      df['listDataSort'] = df['listData'].apply(sorted)


      giving:



       listData listDataSort
      0 [c, f, d, a, e, b] [a, b, c, d, e, f]
      1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]


      Assigning df to a different variable, say df2 still changes everything back to the original source list. Furthermore, how do I create a new dataframe based on an existing dataframe so I can make changes to the new dataframe without making the same changes to the existing dataframe?



      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])

      df2 = df
      print('ndfn', df)
      print('ndf2n', df2)

      df2['listDataSort'] = df2['listData']
      print('ndfn', df)
      print('ndf2n', df2)

      df2['listDataSort'].apply(lambda l: l.sort())
      print('ndfn', df)
      print('ndf2n', df2)


      prints:



      df
      listData
      0 [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3]

      df2
      listData
      0 [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3]

      df
      listData listDataSort
      0 [c, f, d, a, e, b] [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

      df2
      listData listDataSort
      0 [c, f, d, a, e, b] [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3] [5, 2, 1, 4, 3]

      df
      listData listDataSort
      0 [a, b, c, d, e, f] [a, b, c, d, e, f]
      1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]

      df2
      listData listDataSort
      0 [a, b, c, d, e, f] [a, b, c, d, e, f]
      1 [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]


      also:



      df = pd.DataFrame(
      'listData': [
      ['c', 'f', 'd', 'a', 'e', 'b'],
      [5, 2, 1, 4, 3]
      ])
      print('ndfn', df)

      df3 = df
      df3['listDataSort'] = df3['listData'].apply(sorted)
      print('ndfn', df)
      print('ndf3n', df3)


      prints:



      df
      listData
      0 [c, f, d, a, e, b]
      1 [5, 2, 1, 4, 3]

      df
      listData listDataSort
      0 [c, f, d, a, e, b] [a, b, c, d, e, f]
      1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]

      df3
      listData listDataSort
      0 [c, f, d, a, e, b] [a, b, c, d, e, f]
      1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]






      python-3.x pandas pointers memory-management






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 at 21:13









      coldspeed

      136k23148234




      136k23148234










      asked Mar 6 at 20:11









      ClayClay

      619720




      619720






















          1 Answer
          1






          active

          oldest

          votes


















          3














          When you run



          df['listDataSort'] = df['listData']


          All you do is copy the references of the lists to new columns. This means only a shallow copy is performed and both columns reference the same lists. So any change to one column will likely affect another.



          You can use a list comprehension with sorted which returns a copy of the data. This should be the easiest option for you.



          df['listDataSort'] = [sorted(x) for x in df['listDataSort']]
          df

          listData listDataSort
          0 [c, f, d, a, e, b] [a, b, c, d, e, f]
          1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]



          Now, when it comes to the problem of making a copy of the entire DataFrame, things are a little more complicated. I would recommend deepcopy:



          import copy
          df2 = df.apply(copy.deepcopy)





          share|improve this answer


















          • 1





            from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

            – Clay
            Mar 6 at 20:49










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031427%2fdeepcopy-pandas-dataframe-containing-python-objects-such-as-lists%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          When you run



          df['listDataSort'] = df['listData']


          All you do is copy the references of the lists to new columns. This means only a shallow copy is performed and both columns reference the same lists. So any change to one column will likely affect another.



          You can use a list comprehension with sorted which returns a copy of the data. This should be the easiest option for you.



          df['listDataSort'] = [sorted(x) for x in df['listDataSort']]
          df

          listData listDataSort
          0 [c, f, d, a, e, b] [a, b, c, d, e, f]
          1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]



          Now, when it comes to the problem of making a copy of the entire DataFrame, things are a little more complicated. I would recommend deepcopy:



          import copy
          df2 = df.apply(copy.deepcopy)





          share|improve this answer


















          • 1





            from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

            – Clay
            Mar 6 at 20:49















          3














          When you run



          df['listDataSort'] = df['listData']


          All you do is copy the references of the lists to new columns. This means only a shallow copy is performed and both columns reference the same lists. So any change to one column will likely affect another.



          You can use a list comprehension with sorted which returns a copy of the data. This should be the easiest option for you.



          df['listDataSort'] = [sorted(x) for x in df['listDataSort']]
          df

          listData listDataSort
          0 [c, f, d, a, e, b] [a, b, c, d, e, f]
          1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]



          Now, when it comes to the problem of making a copy of the entire DataFrame, things are a little more complicated. I would recommend deepcopy:



          import copy
          df2 = df.apply(copy.deepcopy)





          share|improve this answer


















          • 1





            from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

            – Clay
            Mar 6 at 20:49













          3












          3








          3







          When you run



          df['listDataSort'] = df['listData']


          All you do is copy the references of the lists to new columns. This means only a shallow copy is performed and both columns reference the same lists. So any change to one column will likely affect another.



          You can use a list comprehension with sorted which returns a copy of the data. This should be the easiest option for you.



          df['listDataSort'] = [sorted(x) for x in df['listDataSort']]
          df

          listData listDataSort
          0 [c, f, d, a, e, b] [a, b, c, d, e, f]
          1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]



          Now, when it comes to the problem of making a copy of the entire DataFrame, things are a little more complicated. I would recommend deepcopy:



          import copy
          df2 = df.apply(copy.deepcopy)





          share|improve this answer













          When you run



          df['listDataSort'] = df['listData']


          All you do is copy the references of the lists to new columns. This means only a shallow copy is performed and both columns reference the same lists. So any change to one column will likely affect another.



          You can use a list comprehension with sorted which returns a copy of the data. This should be the easiest option for you.



          df['listDataSort'] = [sorted(x) for x in df['listDataSort']]
          df

          listData listDataSort
          0 [c, f, d, a, e, b] [a, b, c, d, e, f]
          1 [5, 2, 1, 4, 3] [1, 2, 3, 4, 5]



          Now, when it comes to the problem of making a copy of the entire DataFrame, things are a little more complicated. I would recommend deepcopy:



          import copy
          df2 = df.apply(copy.deepcopy)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 20:13









          coldspeedcoldspeed

          136k23148234




          136k23148234







          • 1





            from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

            – Clay
            Mar 6 at 20:49












          • 1





            from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

            – Clay
            Mar 6 at 20:49







          1




          1





          from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

          – Clay
          Mar 6 at 20:49





          from OP: df['listDataSort'] = df['listData'].apply(sorted) is nearly the same solution I had for the columns, not sure which one is faster, perhaps using numpy.sort would be faster still. Thanks for pointing me to deepcopy.

          – Clay
          Mar 6 at 20:49



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031427%2fdeepcopy-pandas-dataframe-containing-python-objects-such-as-lists%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved