I have created a df one column of which contains string values that I want to trim based on a different int value each time. Ex.: From:
I wanna get:
What I tried is the following:
for i in range(len(df.index)): val = df['string'].iloc[i] n = df['length'].iloc[i] df['string'].iloc[i] = val[n:]
However, I keep getting this warning:
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
Any ideas on how I can avoid getting it?
df["String"] = df.apply(lambda x: x["String"][x["lenght"]:], axis=1) >>> df lenght String 0 -3 def 1 -5 hijkl