df == df # df every unit cell df == 0 # df every unit cell
原创
©著作权归作者所有:来自51CTO博客作者基督徒Isaac的原创作品,请联系作者获取转载授权,否则将追究法律责任
# copy
import pandas as pd
df = pd.DataFrame({"co1": [1]})
def foo(df):
df["col2"] = 2
def bar(df):
df = df.copy()
foo(df=df)
print(df) # df就在原地生效
bar(df=df)
# copy
import pandas as pd
df = pd.DataFrame({"co1": [1]})
def foo(df):
df["col2"] = 2
return df
def bar(df):
df = df.copy()
df_2 = foo(df=df)
print(df) # df still take effect in situ
print(df is df_2) # True
bar(df=df)
df == df # df every unit cell
df == 0 # df every unit cell