準備
- messytables をインストール
$ pip install messytables
- テストデータ(test.csv)作成
aze,1,a,1 aze,2,b,2 aze,3,c,3 aze,4,d,4 aze,5,e,5 aze,6,f,6 aze,7,g,7 aze,8,h,8a aze,9,i,9
#!/usr/bin/env python # -*- coding: utf-8 -*- from messytables import CSVTableSet, type_guess fh = open('test.csv', 'rb') table_set = CSVTableSet(fh) row_set = table_set.tables[0] print(type_guess(row_set.sample, strict=True))
実行結果
[String, Integer, String, String]