One possible way to achieve this could be:
import pandas as pd
qry = pd.DataFrame.from_dict({"Keyword": ["NewWordsWithFriends",
"com.fingerarts.sudoku"],
"Game": ["Words With Friends",
"Sudoku by FingerArts"]})
df = pd.DataFrame.from_dict({"user-agent" : ["NewWordsWithFriendsFree/2.3 CFNetwork/672.1.15 Darwin/14.0.0",
"iPhone3,1; iPhone OS 7.1.2; com.fingerarts.sudoku2; 143441-1,24"]})
keywords = qry.Keyword.tolist()
games = qry.Game.tolist()
def select(x):
for key, game in zip(keywords, games):
if key in x:
return game
df["GameName"] = df["user-agent"].apply(select)
This will give:
In [41]: df
Out[41]:
user-agent GameName
0 NewWordsWithFriendsFree/2.3 CFNetwork/672.1.15... Words With Friends
1 iPhone3,1; iPhone OS 7.1.2; com.fingerarts.sud... Sudoku by FingerArts
, , .
, , , , :
, .apply, , , select() ..
, line_profiler (. python ?).