我继续得到一个RuntimeWarning:无法解决的类型:str()< int(),对于无法比较的对象,未定义排序顺序
结果= result.union(其他)来自以下代码.不完全确定我在哪里做错了什么.我正试图让数据集看起来像 this.
结果= 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会将该列强制转换为字符串.谨防.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。