我的理解是,在“=”操作数的情况下,信息从右向左流动。i、 e.a=b意味着b的值被转移到a。如果我后来改变了a,它不应该影响b的值。但在下面的代码中,它正在发生。有人能告诉我为什么会这样吗
df_main=fivminohlc
result=df_main.dtypes
print(result)
result=fivminohlc.dtypes
print(result)
O float64
H float64
L float64
C float64
V int64
dtype: object
O float64
H float64
L float64
C float64
V int64
dtype: object
df_main['Y1']=(df_main['C']-df_main['O'])/df_main['O'] # I have not touched fivminohlc
df_main['Y'] = np.where((df_main.Y1 > .001), 2, 1)
df_main['Y'] = np.where((df_main.Y1 < -.001), 0, 1)
result=df_main.dtypes
print(result)
result=fivminohlc.dtypes
print(result)
O float64
H float64
L float64
C float64
V int64
Y1 float64
Y int32
dtype: object
O float64
H float64
L float64
C float64
V int64
Y1 float64
Y int32
dtype: object
为什么Y和Y1在fivminohlc中显示
因为fivminohlc是一个类的实例,所以当您将它赋给dfèu main时,dfèu main实际上变成了指向fivminohlc的“指针”
dfèu main和fivminohlc都代表同一个实例。因此,通过更新dfu-main,您也在更新fivminohlc
将打印上述代码
请参阅以下文档:https://docs.python.org/3/tutorial/classes.html
第9.3.5节。类和实例变量也可能有用
复印
文档:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.copy.html
这将打印:
相关问题 更多 >
编程相关推荐