python导入excel类库_使用python将excel数据导入类实例

我试图从excel表中导入数据到RPG游戏的类实例列表中。目前我正在尝试使用Pandas,下面是我一直在使用的代码:python3.7.2import pandas as pd

class potion(object):

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()

print(potions)

输出为:

^{pr2}$

我要找的一个例子是要存储的数据,这样每一行都是实例列表的索引:potions = [potion('Crude Hp Potion', 'Hp Potion', 10, 10, 0.5),

potion('Hp Potion', ' hp Potion', 25, 50, 1.0)]

为了达到这个目的,我尝试:for i in potions[0]:

potions.append([potion(i)])

print(potions[0].name)

给了我:TypeError: __init__() missing 4 required positio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值