[英]Save dataframe column and update
I am trying to save a pandas dataframe column instance. 我正在尝试保存熊猫数据框列实例。 but the instance disappears once I make an update in that column, I can't get access to the old instance anymore. 但一旦在该列中进行更新,该实例就会消失,我将无法再访问旧实例。
C= DF.loc[:,'10']
print(C)
DF.loc[:,'10'] = None
print(C)
In the first print I get the last instance of DF.loc[:,'10']
, in the second one I get a None column. 在第一个打印中,我得到了DF.loc[:,'10']
的最后一个实例,在第二个打印中,我得到了None列。 How should I do to save the old instance to use it later? 如何保存旧实例以便以后使用? Does python make an update on variables of the dataframe even when I already saved it? 即使我已经保存了python,python也会对数据框的变量进行更新吗? Thanks for helping. 感谢您的帮助。
In python, setting a variable actually sets a reference to the variable. 在python中,设置变量实际上设置了对该变量的引用。 Variable names in python are references to the original. python中的变量名称是对原始变量的引用。
The following code should make a copy of C
and store in D
以下代码应复制C
并将其存储在D
C= DF.loc[:,'10']
print(C)
D= DF.loc[:,'10'].copy()
DF.loc[:,'10'] = None
print(C)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.