Edit: I had to add this part to my original question as it's relevant.
I have a frame which contains many different prefixes in the name column called dfload.
I use the following command to create a slice called df.
df = dfload.loc[dfload['Name'].str.contains("testData/")]
Original Question continues from here:
Then, I have the following pandas dataframe called df,
name etc etc etc
0 testData/example1 etc ...
1 testData/example2 ...
2 testData/example3
3 testData/example4
...
I want to replace the string testData/ with nothing for the entire column so it looks like this
name etc etc etc
0 example1 etc ...
1 example2 ...
2 example3
3 example4
...
I used the following command df['name'] = df['name'].str.replace('testData/','').
But I get this error,
<ipython-input-20-dae746394d2d>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df['name'] = df['name'].str.replace('testData/','')
The dataframe looks fine, why am I getting this error? What's the "proper" way to do this?
df.loc[:,['name']] = df.name.str.replace('testdata/','')df = dfload.loc[dfload['Name'].str.contains("testData/")]