加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – RuntimeWarning pandas

发布时间:2020-12-20 13:18:36 所属栏目:Python 来源:网络整理
导读:我继续得到一个RuntimeWarning:无法解决的类型:str() int(),对于无法比较的对象,未定义排序顺序 ??结果= result.union(其他)来自以下代码.不完全确定我在哪里做错了什么.我正试图让数据集看起来像 this. df = pd.read_excel('/Users/user/Desktop/------/d
我继续得到一个RuntimeWarning:无法解决的类型:str()< int(),对于无法比较的对象,未定义排序顺序
??结果= result.union(其他)来自以下代码.不完全确定我在哪里做错了什么.我正试图让数据集看起来像 this.

df = pd.read_excel('/Users/user/Desktop/------/data.xlsx')
df.rename(columns={'Product Installed Fiscal Quarter': 'Quarter','Serviceable Product #': 'Product Code','Sold To Customer Name': 'Account','Orderable Product Description': 'Product'},inplace=True)
df.drop(['# of Licenses'],axis=1,inplace=True)

def all_products():
    products = []
    for index,row in df.iterrows():
        if row['Serviceable Product Description'] not in products:
            products.append(row['Serviceable Product Description'])
    products.insert(0,'Account')
    products.insert(1,'Time')
    return products

header = all_products()
xd = pd.DataFrame(columns= header)

def reformatted_data():    
    for index,row in df.iterrows():
        add = [0] * len(header)
        add.insert(0,row['Account'])
        add.insert(1,row['Quarter'])
        index = header.index(row['Serviceable Product Description'])
        add[index] = row['Quantity']
        xd.append(add)
    return xd
reformatted_data()

解决方法

从Excel阅读时,重要的是要记住您的数据类型.熊猫在大多数时候都会做出很好的猜测,但建议明确地投射你将要广泛使用的列.例如,excel中的列可以没有关注字符串和数字但是Pandas要求列是统一类型.因此,Pandas会将该列强制转换为字符串.谨防.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读