pandas の最初に df を確認する関数
df.dtypes() df.info() df.value_counts() df.isnull()
plt.scatter(x1, x2)
pd.scatter_matrix(df)
df.corr()
plt.matshow(...)
df.mean()sotr_values().plot(style='.')
Python の文字列ハイライト機能
サジェストのハイライト機能をPython側で実装
import re # 前方一致 def hilight_apply_pre(word, _list): return [re.sub('^{}'.format(re.escape(word)), '<{0}>{1}</{0}>'.format('em', word), l, 1) for l in _list] # 部分一致 def hilight_apply_sub(word, _list): return [re.sub('{}'.format(re.escape(word)), '<{0}>{1}</{0}>'.format('em', word), l, 0) for l in _list]
suggest_list = [ 'アイフォン', 'アイフォーン', 'アイアイ', 'あいさつ', ] p1 = 'アイ' p2 = 'アイフ' print('hilight_apply_pre(p1, suggest_list)', hilight_apply_pre(p1, suggest_list)) print('hilight_apply_sub(p1, suggest_list)', hilight_apply_sub(p1, suggest_list)) print('hilight_apply_pre(p2, suggest_list)', hilight_apply_pre(p2, suggest_list)) print('hilight_apply_sub(p2, suggest_list)', hilight_apply_sub(p2, suggest_list))
hilight_apply_pre(p1, suggest_list) ['<em>アイ</em>フォン', '<em>アイ</em>フォーン', '<em>アイ</em>アイ', 'あいさつ'] hilight_apply_sub(p1, suggest_list) ['<em>アイ</em>フォン', '<em>アイ</em>フォーン', '<em>アイ</em><em>アイ</em>', 'あいさつ'] hilight_apply_pre(p2, suggest_list) ['<em>アイフ</em>ォン', '<em>アイフ</em>ォーン', 'アイアイ', 'あいさつ'] hilight_apply_sub(p2, suggest_list) ['<em>アイフ</em>ォン', '<em>アイフ</em>ォーン', 'アイアイ', 'あいさつ']
suggest_list = [ 'アアアア', 'アイフォーン', 'アイアイ', 'あいさつ', ] p1 = 'ア' p2 = 'アア' print('hilight_apply_pre(p1, suggest_list)', hilight_apply_pre(p1, suggest_list)) print('hilight_apply_sub(p1, suggest_list)', hilight_apply_sub(p1, suggest_list)) print('hilight_apply_pre(p2, suggest_list)', hilight_apply_pre(p2, suggest_list)) print('hilight_apply_sub(p2, suggest_list)', hilight_apply_sub(p2, suggest_list))
hilight_apply_pre(p1, suggest_list) ['<em>ア</em>アアア', '<em>ア</em>イフォーン', '<em>ア</em>イアイ', 'あいさつ'] hilight_apply_sub(p1, suggest_list) ['<em>ア</em><em>ア</em><em>ア</em><em>ア</em>', '<em>ア</em>イフォーン', '<em>ア</em>イ<em>ア</em>イ', 'あいさつ'] hilight_apply_pre(p2, suggest_list) ['<em>アア</em>アア', 'アイフォーン', 'アイアイ', 'あいさつ'] hilight_apply_sub(p2, suggest_list) ['<em>アア</em><em>アア</em>', 'アイフォーン', 'アイアイ', 'あいさつ']
suggest_list = [ '{}&6^aa|アイフォン', 'アイフォーン{}&6^aa|', 'アイアイ', 'あいさつ', ] p1 = '{}&6^aa|ア' p2 = 'ン{}&6^aa|' print('hilight_apply_pre(p1, suggest_list)', hilight_apply_pre(p1, suggest_list)) print('hilight_apply_sub(p1, suggest_list)', hilight_apply_sub(p1, suggest_list)) print('hilight_apply_pre(p2, suggest_list)', hilight_apply_pre(p2, suggest_list)) print('hilight_apply_sub(p2, suggest_list)', hilight_apply_sub(p2, suggest_list))
hilight_apply_pre(p1, suggest_list) ['<em>{}&6^aa|ア</em>イフォン', 'アイフォーン{}&6^aa|', 'アイアイ', 'あいさつ'] hilight_apply_sub(p1, suggest_list) ['<em>{}&6^aa|ア</em>イフォン', 'アイフォーン{}&6^aa|', 'アイアイ', 'あいさつ'] hilight_apply_pre(p2, suggest_list) ['{}&6^aa|アイフォン', 'アイフォーン{}&6^aa|', 'アイアイ', 'あいさつ'] hilight_apply_sub(p2, suggest_list) ['{}&6^aa|アイフォン', 'アイフォー<em>ン{}&6^aa|</em>', 'アイアイ', 'あいさつ']
pecentile で 外れ値 を調整する。
numpy の clip でpercentile の上限下限で外れ値を調整する。
a = [1,2,3,4,1000,5,6,7,5,4] UPPER_BOUND, LOWER_BOUND = np.percentile(a, [1,99]) b = np.clip(a, UPPER_BOUND, LOWER_BOUND) print(b) [ 1.09 2. 3. 4. 910.63 5. 6. 7. 5. 4. ]
data frame のブログとして
機械学習のおすすめブログ
Datas-frame