我试图将数据从excel表导入到角色扮演游戏的类实例列表中。 现在我正在尝试使用Pandas。 以下是我一直使用的代码。 python3.7. 2导入pandas as PD
类位置(对象) :
def __init__(self,name,types,effects,value,weight ) :
self.name=name
self.types=types
self.effects=effects
self.value=value
self.weight=weight
df=PD.read _ excel (' data/potions.xlsx ',sheet_name='None ' ) )。
potions=df.values.tolist (
是打印(potions )
输出如下。
^{pr2}$
我要找的例子是要保存的数据。 这样,每一行都成为实例列表的索引。 potions=[potion('crudeHp Potion )、' HPpotion )、10、10、0.5、
potion(hp Potion )、(HPpotion )、25、50、1.0 ) ]
为了达到这个目的,我会尝试: for i in potions[0]:
potions.append([potion(I ) ]
打印(potions [0].name ) )。
它给了我TypeError: __init__ () missing4requiredpositionalarguments 3360 ' types '、' effects '、' value '和and '
我使用的表格数据如下。 Name Type Effect Price Weight
0 Crude Potion Potion 10 10 0.5
1惠普potion惠普potion 25 50 1.0
2 superiorhppotionhppotion 501001.5
3 Crude Mp Potion Mp Potion 5 5 0.5
4 Mp Potion Mp Potion 15 50 1.0
5 superiormppotionmppotion 301001.5
我不太清楚我错过了什么。 我希望你能帮助我,但我好像哪里都找不到可以说明如何实现它的地方。
谢谢你。 在