从 pandas json 文件中提取数据
Extraction from data from pandas json file
我有以下 json 数据文件,我已将其转换为 pandas 数据帧。栏目如下
Index(['id', 'title', 'abstract', 'content', 'metadata'], dtype='object')
我对'metadata'列特别感兴趣,该列的一个元素看起来像
df_json.loc[78, 'metadata']
"{'classification': {'name': 'Manufacturing, Transport & Logistics'}, 'subClassification': {'name': 'Warehousing, Storage & Distribution'}, 'area': {'name': 'Southern Suburbs & Logan'}, 'location': {'name': 'Brisbane'}, 'suburb': {'name': 'Milton'}, 'workType': {'name': 'Casual/Vacation'}}"
所以我想制作从 'metadata' 列中提取信息的列,例如位置。我不确定如何提取它并将其放在同一个 json 文件旁边,并添加了位置等列
id title abstract content metadata clean_content
0 38915469 Recruitment Consultant We are looking for someone to focus purely on ... <HTML><p>Are you looking to join a thriving bu... {'standout': {'bullet1': 'Join a Sector that i... Are you looking to join a thriving business th...
1 38934839 Computers Salesperson - Coburg Passionate about exceptional customer service?... <HTML><p>· Casual hours as r... {'additionalSalaryText': 'Attractive Commissio... middotnbspnbspCasual hours as required transit...
2 38946054 Senior Developer | SA Readifarians are known for discovering the lat... <HTML><p>Readify helps organizations
you can use pandas.json_normalize
正在应用您的字符串
pd.json_normalize(eval(json_string))
#o/p
如果这对你有用,那么你可以试试
df["metadata"].apply(lambda x: pd.json_normalize(eval(x)))
我有以下 json 数据文件,我已将其转换为 pandas 数据帧。栏目如下
Index(['id', 'title', 'abstract', 'content', 'metadata'], dtype='object')
我对'metadata'列特别感兴趣,该列的一个元素看起来像
df_json.loc[78, 'metadata']
"{'classification': {'name': 'Manufacturing, Transport & Logistics'}, 'subClassification': {'name': 'Warehousing, Storage & Distribution'}, 'area': {'name': 'Southern Suburbs & Logan'}, 'location': {'name': 'Brisbane'}, 'suburb': {'name': 'Milton'}, 'workType': {'name': 'Casual/Vacation'}}"
所以我想制作从 'metadata' 列中提取信息的列,例如位置。我不确定如何提取它并将其放在同一个 json 文件旁边,并添加了位置等列
id title abstract content metadata clean_content
0 38915469 Recruitment Consultant We are looking for someone to focus purely on ... <HTML><p>Are you looking to join a thriving bu... {'standout': {'bullet1': 'Join a Sector that i... Are you looking to join a thriving business th...
1 38934839 Computers Salesperson - Coburg Passionate about exceptional customer service?... <HTML><p>· Casual hours as r... {'additionalSalaryText': 'Attractive Commissio... middotnbspnbspCasual hours as required transit...
2 38946054 Senior Developer | SA Readifarians are known for discovering the lat... <HTML><p>Readify helps organizations
you can use pandas.json_normalize
正在应用您的字符串
pd.json_normalize(eval(json_string))
#o/p
如果这对你有用,那么你可以试试
df["metadata"].apply(lambda x: pd.json_normalize(eval(x)))