首页 > 解决方案 > 我在 Jupyter 中得到的输出与在 Spyder 中的不同

问题描述

我在附加的 Jupyter 中编写了一个脚本。最后,要求输出两个并排的表,如下所示

在此处输入图像描述

虽然我在 Jupyter 中得到了结果,但是当我在 Spyder 中运行相同的程序时,我无法得到相同的结果。有没有办法在 Spyder 中做到这一点?

PS:这些文件是来自kaggle 比赛的代币:

要运行此脚本,您只需要product_category_name_english.csv,olist_products_dataset.csvolist_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")

标签: pythonanacondajupyterspyder

解决方案


推荐阅读