python pandas数据框列的字符串值看起来像字典列表吗?

我有一个数据框列,其中包含字符串值(已编辑) 数据框列的类型为字符串BUT(已编辑) 它的值看起来像字典列表(已编辑) 我如何从该字符串中提取一些键值? 该STRING值类似于字典列表。

当键“ job”的值为“ Director”时,如何提取[{ 'credit_id': '549e9edcc3a3682f2300824b','department': 'Camera','gender': 2,'id': 473,'job': 'Additional Photography','name': 'Brian Tufano','profile_path': None },{ 'credit_id': '52fe4214c3a36847f8002595','department': 'Directing','id': 578,'job': 'Director','name': 'Ridley Scott','profile_path': '/oTAL0z0vsjipCruxXUsDUIieuhk.jpg' },{ 'credit_id': '52fe4214c3a36847f800259b','department': 'Production','id': 581,'job': 'Producer','name': 'Michael Deeley',{ 'credit_id': '52fe4214c3a36847f800263f','department': 'Writing','id': 584,'job': 'Novel','name': 'Philip K. Dick','profile_path': '/jDOKJN8SQ17QsJ7omv4yBNZi7XY.jpg' },{ 'credit_id': '549e9f85c3a3685542004c7b','department': 'Crew','job': 'Thanks',{ 'credit_id': '52fe4214c3a36847f800261b','id': 583,'job': 'Screenplay','name': 'Hampton Fancher','profile_path': '/lrGecnLhzjzgwjKHvrmYtRAqOsP.jpg' } ] 键的值?

{{1}}
chu20061 回答:python pandas数据框列的字符串值看起来像字典列表吗?

您可以通过将列表转换为pandas数据框来实现: pandas.DataFrame

import pandas as pd
df =pd.DataFrame(yourList)    
df['name'][df['job']=="Director"] # you will get a series of all the names matching your condition.

或者还有一种方法是使用.loc []

df.loc[df["job"]=="Director",["name"]] # You will get a dataframe with name column having all the names matching the condition.
,
import pandas as pd
df =pd.DataFrame(LIST)
Name=df['name'][df['job']=="Director"]
print('Name =',Name)
本文链接:https://www.f2er.com/3169909.html

大家都在问