因文本類似性熱度統計(python版)需求中要根據故障類型進行分組統計,須要對excel進行分組後再分詞統計,簡單記錄下,有須要的朋友能夠直接拿走,不客氣!html
採用pandas包首先進行分組,而後獲取具體明細再進行分詞處理(分詞處理這裏就不展開了),只介紹下python下excel分組,而後對具體明細進行處理。python
import pandas as pd if __name__ == '__main__': inputfile = '軟件老王-source.xlsx' data = pd.read_excel(inputfile) grp1 = data.groupby('待分類列') rcount = 1 for name, group in grp1: print(group) name = name.replace('\n', '').replace('/', '') for i in range(len(group)): row = group.iloc[i].values # 返回一個list cell = row[1] if cell is None: continue if not isinstance(cell, str): continue item = cell.strip('\n\r').split('\t') string = item[0] if string is None or len(string) == 0: continue else: print('這裏獲取group後明細值,軟件老王能夠單獨處理,類別:' +name + '具體值:' + string)
待分類列 緣由 0 軟件老王1 主機不能加電 1 軟件老王1 有時不能加電 2 軟件老王1 開機加電 這裏獲取group後明細值,軟件老王能夠單獨處理,類別:軟件老王1具體值:主機不能加電 這裏獲取group後明細值,軟件老王能夠單獨處理,類別:軟件老王1具體值:有時不能加電 這裏獲取group後明細值,軟件老王能夠單獨處理,類別:軟件老王1具體值:開機加電 待分類列 緣由 3 軟件老王2 自檢報錯或死機 4 軟件老王2 機器噪音大 這裏獲取group後明細值,軟件老王能夠單獨處理,類別:軟件老王2具體值:自檢報錯或死機 這裏獲取group後明細值,軟件老王能夠單獨處理,類別:軟件老王2具體值:機器噪音大 待分類列 緣由 5 軟件老王3 噪音問題 這裏獲取group後明細值,軟件老王能夠單獨處理,類別:軟件老王3具體值:噪音問題
待分類列 | 緣由 |
---|---|
軟件老王1 | 主機不能加電 |
軟件老王1 | 有時不能加電 |
軟件老王1 | 開機加電 |
軟件老王2 | 自檢報錯或死機 |
軟件老王2 | 機器噪音大 |
軟件老王3 | 噪音問題 |
I’m 「軟件老王」,若是以爲還能夠的話,關注下唄,後續更新秒知!歡迎討論區、同名公衆號留言交流!excel