使用 Drop 时,pandas 中非相关 DF 中的相同列丢失

same Columns go missing in non related DF in pandas when use Drop

我很困惑....当我从 dfocus1 中删除 cols 'Focus2','Score2','Focus3','Score3' 时,它会在 dfocus2 中删除相同的 cols

为什么?

'''

dfocus1=df
dfocus2=df
dfocus3=df

print('\nTable data',dfocus2.info(memory_usage='deep'))

dfocus1.drop(['Focus2','Score2','Focus3','Score3'], axis=1,inplace=True)

print('\nTable data',dfocus2.info(memory_usage='deep'))
'''

这是因为 dfocus1dfocus2 指向同一个对象 (df)。

创建 dfcopy,然后删除列:

dfocus1=df.copy()
dfocus2=df.copy()