By chance, I saw other people’s code and found that some of them would pass in parameters. Do a copy and experiment. Regarding the input parameters, is it a pointer or a reference?
Let me talk about my conclusion:
- If the input is a simple type, then the input should be a quoted value,
- If the type of df is passed in, then the pointer is passed in.
- The modification you make in the function will still change the original df. It is best to copy the complex type of variables in the function!
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:778463939
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
import pandas as pd
def qqq(a,b):
a.loc[1,1] = 9999
b = 88888
del a
del b
if __name__ == '__main__':
aaa = pd.DataFrame([[1,2,3],[4,5,6]])
bbb = 123000
qqq(aaa, bbb)
print('aaa:\n',aaa,'\n')
print('bbb:',bbb)
Output:
aaa:
0 1 2
0 1 2 3
1 4 9999 6
bbb: 123000