1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import pandas as pd
def excel_deal(path, uid): keys = { '直播间名称': 'title', '开播时间': 'startLive', '直播时长': 'liveTime', '观看人次': 'totalUser', '直播商品数': 'goodsNum', '销量': 'sales', '销售额': 'gmv', '链接': 'url', '平均在线': 'userCount', 'UV价值': 'uvVal', '坑产': 'pitProduction', '客单价': 'unitPrice', '销售转化率': 'salesConRate', '退货件数': 'refund', '退货率': 'refundRate', '点赞数': 'digg', '新增粉丝': 'fansInc', '转粉率': 'fansIncRate', '人均停留时长': 'avgUserDuration', '人数峰值': 'userNum', '分享数': 'shareCount', '观看人数': 'watchNum', '分钟销量': 'salesMin', '分钟销售额': 'gmvMin', '分钟流量': 'watchIncMin', '互动率': 'itemRate',
} cols = [] clos_list = [] for k, v in keys.items(): cols.append(k) if v == "": continue else: clos_list.append(v) df_dict = {} df = pd.read_excel(io=path, usecols=cols, na_values='#N') df.fillna('', inplace=True)
df_list = [] for i in df.index.values: df.rename(columns=keys, inplace=True)
df_line = df.loc[i, clos_list].to_dict() df_list.append(df_line) df_dict['data'] = df_list
return df_dict
if __name__ == '__main__': res = excel_deal("./2022-10-24-2022-11-23.xlsx", "ss") print(res)
|