|
Python+Pandas:
import pandas as pd
df = pd.read_excel('pandas exercise/sample464.xlsx', usecols='a,b,h,i,j,k', header=3)
df1 = pd.read_excel('pandas exercise/sample464.xlsx', usecols='l', skiprows=3, header=None, nrows=16)
df = df.groupby(df.columns[:-1].to_list(), as_index=False).sum()
df['货商名称'] = df['货商名称'].astype('category')
lst = df1.iloc[:, 0].to_list()
lst1 = df['货商名称'].cat.categories.to_list()
lst2 = [i for i in lst if i in lst1]
df['货商名称'] = df['货商名称'].cat.reorder_categories(lst2)
df.sort_values('货商名称')
|
|