import pandas as pd
DF1 = pd.DataFrame({'name': ['abc in first line of text', 'abc of second line of text', 'def on third line of text'], 'other': [10, 20, 30]})
DF2 = DF1[DF1.name.str.startswith('abc')]
DF2['name'] = [x.split('abc')[1][4:].title() for x in DF2['name']]
print(DF2)
Updating a column in a pandas dataframe using the code above gives the following warning:
SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
The output is correct.
Any suggestions how to rewrite this code to prevent this warning?