Skip to content

Instantly share code, notes, and snippets.

@HirofumiYashima
Created February 8, 2015 03:44
Show Gist options
  • Save HirofumiYashima/e54090e365c1108a44b5 to your computer and use it in GitHub Desktop.
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
['1%', '7%', 'NULL', '8%', 'na', '']
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