I am creating a NAME column in a DataFrame and set its value based on substrings contained in another column.
Is there a more efficient way to do this?
import pandas as pd
df = pd.DataFrame([['www.pandas.org','low'], ['www.python.org','high']],
columns=['URL','speed'])
print(df.head())
df['Name'] = df['URL']
print(df.head())
#set Name based on substring in URL
df.loc[df['Name'].str.contains("pandas", na=False), 'Name'] = "PANDAS"
df.loc[df['Name'].str.contains("python|pitone", na=False), 'Name'] = "PYTHON"
print(df.head())