I want to parse 3 additional information(browser, device and os) from below sample csv file->AGN column
_time,AGN,emoloyee
2022-08-30T17:54:18.796+0000,"[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36]",employeeA
2022-08-30T12:56:35.927+0000,"[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36]",employeeB
2022-06-06T07:27:31.647+0000,"[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27]",employeeC
Here is the code i used:
import pandas as pd
from user_agents import parse
df1_identifyDevice['AGN']=df1_identifyDevice['AGN'].str.strip('[]')
for item in df1_identifyDevice['AGN']:
user_agent = parse(item)
print(item)
df1_identifyDevice['browser'] = user_agent.browser.family
df1_identifyDevice['os'] = user_agent.os.family
df1_identifyDevice['device'] = user_agent.device.family
But above seems not parse the information correctly.
- for browser- it all return 'Safari' as result
- for 'os' - it all return 'Mac os c' as result
- for 'device' - it all return 'Mac' as reuslt
Please refer to below running result:
Can you please help take a look what's wrong with the code?