#coding=utf-8
import pandas as pd
from sklearn.decomposition import PCA
#读取四张表的数据
prior=pd.read_csv("./data/order_products__prior.csv")
products=pd.read_csv("./data/products.csv")
orders=pd.read_csv("./data/orders.csv")
aisles=pd.read_csv("./data/aisles.csv")
#合并四张表到一张表中(用户-物品类别)
_mg=pd.merge(prior,products,on=['product_id','product_id'])
_mg=pd.merge(_mg,orders,on=["order_id","order_id"])
meg=pd.merge(_mg,aisles,on=(["aisle_id","aisle_id"]))
cross=pd.crosstab(meg["user_id"],meg["aisle"])
#进行主成分分析
pca=PCA(n_components=0.95) #保留95%的有效数据
data=pca.fit_transform(cross)
print(data)