csvのファイルの数字の部分だけ消して、フォルダ内のテキストを結合

csvファイルを一つのテキストファイルにまとめたかったので。

f:id:alakialaca:20160805193242p:plain

↑エクセルで開いたとき。

f:id:alakialaca:20160805193246p:plain

↑メモ帳で開いたとき。

 

この数字の部分消したいと思ったので。

 正規表現でたくさん数字ある部分を消して結合した。

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob
import re


f = open("ketsu.txt","w") #これに全てを突っ込みたい。
files = glob.glob('/media/araki/HD-LBU3_NTFS/*csv')

for file_count in files:
    for i in open(file_count,"r"):
        itemList = i.split(' ')
        for word in itemList:
            word = re.sub("\d{4,},\d{4,},","",word)
            word = re.sub("\.","",word)
            print word
            if word == "":
                continue
            t=word.count("\n")
            if t == 1:
                f.write(word)
                continue
            f.write(word + " ")

 

 これ絶対他に賢い方法あるよ〜