import pandas as pd def write_to_excel(count_dict): data = {'关键词': list(count_dict.keys()), '数量': list(count_dict.values())} df = pd.DataFrame(data) df = df.sort_values(by='数量', ascending=False) df.to_excel('danmaku_count.xlsx', index=False)