Created
February 8, 2015 03:44
-
-
Save HirofumiYashima/e54090e365c1108a44b5 to your computer and use it in GitHub Desktop.
Python で、NULL や n.a, N.A, 空欄 を含んだ 数値データ のリスト を、数値要素 だけ パーセント表示 に変えて、それ以外の要素はもとの値のまま変えないで出力して、新しいリストを得るコード例 ref: http://qiita.com/HirofumiYashima/items/96d12e215125bebc207c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['1%', '7%', 'NULL', '8%', 'na', ''] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
import types | |
data_lit_3 = [0.01, 0.07, 'NULL', 0.08, 'na', ''] | |
['%g%%' % y if type(y)==Decimal else y for y in [Decimal(str(x))*Decimal('100') if type(x)==float else x for x in data_list_3]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment