在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python字典寫進(jìn)表格當(dāng)中

python字典寫進(jìn)表格當(dāng)中

import os
from collections import Counter
sumsdata = []
for fname in os.listdir(os.getcwd()):
    if os.path.isfile(fname) and fname.endswith('.txt'):
        with open(fname,'r',encoding="utf-8") as fp:
            data = fp.readlines()
            fp.close()
        sumsdata += [line.strip().lower() for line in data]
cnt = Counter()
for word in sumsdata:
    cnt[word] += 1
cnt = dict(cnt)
print(cnt)
for key,value in cnt.items():
    dic = key + ":" + str(value)
    # print(data)


‘.txt’里大概是這樣的{中國 北京 中國 北京 上海 重慶
}

怎么把數(shù)據(jù)寫進(jìn)表格當(dāng)中方便查詢

回答
編輯回答
擱淺

print 到txt,用excle打開,選擇分隔符:,導(dǎo)出。

2017年8月18日 17:29