python – RuntimeWarning pandas

我继续得到一个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会将该列强制转换为字符串.谨防.

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...