首页 > 编程知识 正文

python代码库,python进阶教程

时间:2023-05-05 00:00:08 阅读:128081 作者:251

我试图将数据从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

我不太清楚我错过了什么。 我希望你能帮助我,但我好像哪里都找不到可以说明如何实现它的地方。

谢谢你。 在

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。