我有一个以object为值的Dict,我想从中创建一个DF (忽略“南”)
list_of_actors[key] = value
key -> string
value -> Actor()
class Actor:
def __init__(self,title,link):
self.link = link
self.title = title
self.count = 1
self.yearOfBirth ="NaN"
self.countryOfBirth ="NaN"
self.numberOfAwards = "0"
columns = ['Name', 'Year of birth', 'Country of birth', 'Awards']
Name = self.title
Year of birth = self.yearOfBirth
Country of birth = self.countryOfBirth
Awards = self.numberOfAwards
在尝试下面的代码之前,您应该只在列列表中添加字段,对于这个特定的示例,它们是:name、year、country和awards。 然后,您可以尝试:
可以使用pandas创建数据帧。你知道吗
字典的键是列名,值是行。所以你会得到:
对我来说,你想要什么还不是100%清楚。但我假设您想将
Actor
实例列表转换为数据帧。你知道吗我们可以在
Actor
上添加一个to_dict()
方法,将参与者序列化到字典中,并通过简单地使用pandas.DataFrame()
将此类字典的列表转换为数据帧:相关问题 更多 >
编程相关推荐