python - 我在 Jupyter 中得到的输出与在 Spyder 中的不同
问题描述
我在附加的 Jupyter 中编写了一个脚本。最后,要求输出两个并排的表,如下所示
虽然我在 Jupyter 中得到了结果,但是当我在 Spyder 中运行相同的程序时,我无法得到相同的结果。有没有办法在 Spyder 中做到这一点?
PS:这些文件是来自kaggle 比赛的代币:
要运行此脚本,您只需要
product_category_name_english.csv
,olist_products_dataset.csv
和olist_order_items_dataset.csv
数据文件
代码:
import pandas as pd
import numpy as np
from IPython.display import display, HTML
def Problem(file_name1, file_name2, file_name3):
product_category = pd.read_csv(file_name1, sep=",")
product_category.head()
olist_products = pd.read_csv(file_name2, sep=",")
olist_products.head()
olist_order = pd.read_csv(file_name3, sep=",")
olist_order.head()
data = pd.merge(pd.merge(product_category, olist_products), olist_order)
data["freight_percent"] = (data["freight_value"]/(data["freight_value"]+data["price"]))*100
Data_Categorized = data.pivot_table(index="product_category_name_english", values=(["freight_percent"]), aggfunc="mean")
top_10 = Data_Categorized.sort_values("freight_percent", ascending=False)[:10]
top_10 = top_10.reset_index()
top_10.index = top_10.index+1
bottom_10 = Data_Categorized.sort_values("freight_percent")[:10]
bottom_10 = bottom_10.reset_index()
bottom_10.index = bottom_10.index+1
result = pd.concat([top_10, bottom_10], axis=1, sort=False)
print("\t\t\033[94m\033[1mTOP 10 \t\t\t\t BOTTOM 10")
display (result)
Problem("product_category_name_translation.csv","olist_products_dataset.csv","olist_order_items_dataset.csv")
解决方案
推荐阅读
- java - 我可以在初始化设置的内容视图后更改 Android Button 的样式吗?
- python - 运行 python 项目时出现 web_socket 错误
- c# - 如何获得执行的声明成员?
- aws-lambda - 如果 Lambda 函数抛出错误(不是超时),如何向 DLQ 发送错误?
- python - 如何对作为字典值的列表进行排序?
- node-red - 多个输入节点红色函数python
- c - sprintf 组合字符数组
- python - 如何在最后一步之前保存我的表单向导?
- java - 处理错误:InvalidGrantException,错误凭据
- ios - 当 prefersLargeTitles 为 true 时自定义 NavigatioItem TitleView