我用Jupyter写了一个脚本,附在后面。最后,两个表并排请求输出,如下所示
虽然我在Jupyter中得到了这个结果,但是当我在Spyder中运行相同的程序时,我不能得到相同的结果。在Spyder有没有办法做到这一点?你知道吗
PS:文件已从kaggle competition标记:
To run this script you need only
product_category_name_english.csv
,olist_products_dataset.csv
andolist_order_items_dataset.csv
data files
代码:
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")
目前没有回答
相关问题 更多 >
编程相关推荐