#author("2020-02-07T05:18:05+00:00","","")
[[seminar-personal/chin2017]]
**おさらい [#o52b72da]
前回ゼミより抜粋
 いまやっていること
 少ないクラスタに分類されたペアが所属しているCSVファイルを特定する。
 少ないクラスタを排除
 基準がわからない。
 10個以下のクラスタ数
 100個以下のクラスタ数
 1000個以下のクラスタ数、はそれぞれ何個か?

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 #20200117 pathを出力
 from gensim.models import Word2Vec
 import pandas as pd
 import pandas.io.common
 import numpy as np
 import codecs
 import random
 import os
 import getenc
 import time
 import re
 import sys
 from progressbar import *
 start = time.time()
 def is_text(item):
     try:
        if re.search('^[A-ZA-Za-za-zⅠ-Ⅹ0-90-9%.・・.::\"’′″°〜~―ー-−‐_//○〇*()-×●★△&…〒〃㎡  	]+$',item):#記号・英語・数字等
            return False
        elif re.search('^[0-90-9①-⑳-―ー-−‐()(),,.△><%  ]+$',item):#記号・英語・数字等2
            return False
        elif re.search("(https?|ftp|http)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)",item):#URL
            return False
        elif re.search("[\s\S]{30}",item):#30文字以上
            return False
        elif re.search('[︰-@~_「」[\a-zA-Z//-―-−‐←→↑┌↓?\\\]',item):#特殊文字2:円マック 
            return False
        else:
            return True
     except TypeError:
         return False
     else:
         return False
 def is_item_name(item):
     try:
        if re.search('^[A-ZA-Za-za-zⅠ-Ⅹ0-90-9%.・・.::\"’′″°〜~―ー-−‐_//○〇*()-×●★△&…〒〃㎡  	]+$',item):#記号・英語・数字等1
            return False
        elif re.search('^[0-90-9①-⑳-―ー-−‐()(),,.△><%  ]+$',item):#記号・英語・数字等2
            return False
        elif re.search('^[0-90-9年月日円通平成度第回銭末日現在№(),.]+$',item):#特殊文字1
            return False
        elif re.search('[︰-@~_「」[\a-zA-Z//-―-−‐←→↑┌↓?\\\]',item):#特殊文字2:円マック 
            return False
        elif re.search('[a-zA-Z:{}]',item):#特殊文字3:英文字含めている場合
            return False
        elif re.search('([0-90-9]{2,4})(-|ー|−)([0-90-9]{2,4})',item):#特殊文字4:住所番地など除外
            return False
        elif re.search('^[0-90-9①-⑳]',item):#特殊文字5
            return False
        elif re.search('^[ぁ-ゟ]+$',item):#ひらがなのみ (20191217追記)
            return False
        elif re.search("[\s\S]{15}",item):#15文字以上
            return False
        #elif re.search("^[\s\S]{0,1}$",item):#1文字のみ
        #    return False
        else:
            return True
     except TypeError:
         return False
     else:
         return False
 print("CSV list reading...")
 csv_list_files="prep2_csv_list.csv"
 with codecs.open(csv_list_files, 'r','utf8') as f:
     csv_list =f.readlines()
 len_csv =29995#len(csv_list)
 print('The number of csv list:',len_csv)
 k=0
 item_name = []
 exclusion_list =[]
 re_list =[]
 re_listcheck =[]
 WIDGETS = ['Progress of making dataset: ',Percentage(), ' ', Bar('#'),' ', Timer(),' ', ETA(), ' ', FileTransferSpeed()]
 pbar=ProgressBar(widgets=WIDGETS, maxval=len_csv).start()#プログレスバーのスタート
 for n in range(0,len_csv):
     fname=csv_list[n].strip()#空白文字を除外    
     if (os.path.exists(fname)):#サイズ制限:and os.path.getsize(fname) <5242880):#5MB:5242880 and os.path.getsize(fname) <5242880
         moji_code=getenc.getEncode(fname)
         if moji_code is not None :
             with codecs.open(fname,'rb',moji_code) as f:
                 try:
                     df = pd.read_csv(f,delimiter =",")
                     k=k+1
                     for col in df.columns:
                         for data in df[col]:
                             #除外1:型(数字を除外)
                             if ((type(data) is int) or(type(data) is float) or (pd.isnull(data) == True) ):
                                 continue
                             #除外2:正規表現で除外
                             if ((is_text(data) ==False) or (is_item_name(col) ==False)):
                                 continue
                             #除外3:空白文字除外
                             data =re.sub('[ | |"|\n|\r|\t|\vt|<br>]','',data)
                             data =re.sub(',',',',data)
                             col =re.sub('[ | |"|\n|\r|\t|\vt|<br>]','',col)
                             col =re.sub(',',',',col)
                             col =re.sub('[0-90-9①-⑳.-―ー-−‐]{0,10}$','',col)#項目名の後ろに数字等の場合の除外処理
                             #除外4:空を
                             if(len(col)==0 or len(data)==0):
                                 continue 
                             if [data,col] not in re_listcheck:
                                 re_list.append([data,col,fname])
                                 re_listcheck.append([data,col])
                             if col not in item_name:
                                 item_name.append(col)
                 except pandas.io.common.EmptyDataError:
                     exclusion_list.append(fname)
                     print("ERROR: {} is empty".format(fname))
                 except pandas.io.common.AbstractMethodError:
                     print("ERROR: {} is AbstractMethodError".format(fname))
                     exclusion_list.append(fname)
                 except pandas.io.common.DtypeWarning:
                     print("ERROR: {} is DtypeWarning".format(fname))
                     exclusion_list.append(fname)
                 except pandas.io.common.ParserError:
                     print("ERROR: {} is ParserError".format(fname))
                     exclusion_list.append(fname)
                 except pandas.io.common.ParserWarning:
                     print("ERROR: {} is ParserWarning".format(fname))
                     exclusion_list.append(fname)
                 except Exception as e:
                     print("%s 's error is %s"%(format(fname),format(e)))
                     exclusion_list.append(fname)
         else:
             exclusion_list.append(fname)
     else:
         exclusion_list.append(fname)
     pbar.update(n)#処理の進捗状況をプログレスバーとして表示
 pbar.finish()#プログレスバーの終了
 df2 = pd.DataFrame(re_list,columns=['item','item_data','path'])
 df2.to_csv("pre2_csv_items_all_0_29995.csv",index=False,encoding="utf-8-sig")
 item_name_list = pd.DataFrame(item_name,columns=['item_name'])
 item_name_list.to_csv("items_name_all_0_29995.csv",index=False,encoding="utf-8-sig")
 df3 = pd.DataFrame(exclusion_list,columns=['path'])
 df3.to_csv("exclusion_list_all_0_29995.txt",index=False,encoding="utf-8-sig")
 print("done")
 print('The number of processed csv :',k)
 print('The number of discarded csv:',len_csv-k)
 process_time = format(time.time() - start)
 print('Execution time is %s s'%process_time)
**調査について [#pe5c981e]
-5回以下
|クラスタ|回数|中身|path|
|4|1|北中|./opendata_l_5-prep2/www.pref.fukui.lg.jp/doc/toukei-jouhou/opendata/list1_jikokusuii_d/fil/jikokusuii2009.csv|
|5|2|なす、見出し|./opendata_l_5-prep2/www.pref.kanagawa.jp/osirase/1197/ktv/csv/pickup.csv|
|6|3|歳入出、県内の出|./opendata_l_5-prep2/www.city.nagaoka.niigata.jp/shisei/cate10/toukei/file/toukei_27.csv|
|7|4|当落|./opendata_l_5-prep2/www.city.setagaya.lg.jp/kurashi/107/788/790/d00138488_d/fil/senkan.csv|
|13|2|で医療対|./opendata_l_5-prep2/www.pref.niigata.lg.jp/HTML_Article/19-01,26.csv|
|15|2|特にない、簡舗を含まない|./opendata_l_5-prep2/www.city.kawasaki.jp/170/cmsfiles/contents/0000066/66733/shimin2015-02-q-all.csv|
|15|2|特にない、簡舗を含まない|./opendata_l_5-prep2/www.pref.fukushima.lg.jp/uploaded/attachment/155133.csv|
|38|2|る世帯|./opendata_l_5-prep2/www.city.kobe.lg.jp/information/data/statistics/toukei/kokutyou/7data/073k10.csv|
|39|3|う||
|46|2|動機付け支援|./opendata_l_5-prep2/www.city.sumida.lg.jp/kuseijoho/sumida_info/opendata/opendata_ichiran/gyoseikisosiryo/20160401/7.files/7-1-2.csv|
|74|5|ページアクセス総計、全部公開、稼働世帯|./opendata_l_5-prep2/opendata.pref.miyazaki.lg.jp/dataset/414/resource/2724/10803007 考古博物館ホームページアクセス統計(H27.7作成).csv|
|74|5|ページアクセス総計、全部公開、稼働世帯|./opendata_l_5-prep2/www.city.sumida.lg.jp/kuseijoho/sumida_info/opendata/opendata_ichiran/gyoseikisosiryo/20160401/1-5.files/1-5-1.csv|
|74|5|ページアクセス総計、全部公開、稼働世帯|./opendata_l_5-prep2/www.pref.niigata.lg.jp/HTML_Article/04-03,10.csv|
|74|5|ページアクセス総計、全部公開、稼働世帯|./opendata_l_5-prep2/www.pref.niigata.lg.jp/HTML_Article/04-08,28.csv|
|97|3|函館アリーナ前、函館どつく前、三宮・花時計前||
|110|1|残留農薬|./opendata_l_5-prep2/www.pref.niigata.lg.jp/HTML_Article/499/648/23-04,0.csv|
|149|1|交流|./opendata_l_5-prep2/www.city.nagaoka.niigata.jp/shisei/cate10/kokusaikouryu/file/01-01.csv|
|150|1|よりみちクルーズ|./opendata_l_5-prep2/www.city.kagoshima.lg.jp/jousys/documents/3-29_feri-jikokuhyoukagoshimakousyukkou.csv|
-path:\\10.200.11.9\home\N\chin\20200207
-[[前回報告>http://f-lab.mydns.jp/index.php?chin2017-20200110]]
-上記のCSVを見ると、変なファイルが多いので、除外する必要である。
--方法として、手作業で確認?(手間がかかると思う)
--出現する回数より除外?10回?100回?200回?よりノイズとして削除を検討


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS