Slicing a Pandas DataFrame into a new DataFrame

前端 未结 1 2001
情书的邮戳
情书的邮戳 2020-12-18 23:34

I would like to slice a DataFrame with a Boolean index obtaining a copy, and then do stuff on that copy independently of the original DataFrame.

Judging from this a

相关标签:
1条回答
  • 2020-12-19 00:28

    You need copy with boolean indexing, new DataFrame constructor is not necessary:

    d2 = d1[d1.a > 1].copy()
    

    Explanation of warning:

    If you modify values in d2 later you will find that the modifications do not propagate back to the original data (d1), and that Pandas does warning.

    0 讨论(0)
提交回复
热议问题