import pandas as pd
df = pd.read_excel("合并fitment.xlsx")
print(len(df))
skus = df.SKU.drop_duplicates()
result = []
for sku in skus:
df_sub = df[df.SKU == str(sku)]
makes = df_sub.Make.drop_duplicates()
for make in makes :
df_sub_sub = df_sub[df_sub.Make == make]
models = df_sub_sub.Model.drop_duplicates()
for model in models:
df_sub_sub_sub = df_sub_sub[df_sub_sub.Model ==model]
year = df_sub_sub_sub.Year
year_min = year.min()
year_max = year.max()
arr = [year_min, "-",year_max , make , model]
s = ""+str(year_min)+" - "+str(year_max)+" "+ str(make)+" "+str(model)
result.append([sku , s])
df = pd.DataFrame(result , columns=["SKU","fitment"])
df.to_csv("fitment_combine.csv" , index=False)
删除重复元素 drop_duplicates()
最新推荐文章于 2024-05-17 09:20:11 发布