I'm trying to change a new data frame's column using apply function to another df, but both data frames' columns changes.
df = pd.DataFrame([['x1','x2'],['y1','y2']],columns=['A','B'])
A | B |
---|---|
x1 | x2 |
y1 | y2 |
lst = []
def getbinary(x):
if x not in lst:
lst.append(x)
return lst.index(x)
modeldf = df
modeldf['A'] = df['A'].apply(getbinary)
modeldf and df after this code:
A | B |
---|---|
0 | x2 |
1 | y2 |
source https://stackoverflow.com/questions/74565374/pandas-apply-works-as-inplace-true
Comments
Post a Comment