Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf126071

Browse files
authored
Merge pull request#179 from Minku-Koo/osskoo
to update python code for clean code
2 parents9a93481 +bb050f3 commitf126071

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

‎python/pandasCommand.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ def _vp_get_columns_list(df):
3636
cInfo['value']="'{}'".format(c)
3737
eliftype(c).__name__=='Timestamp':
3838
cInfo['value']=str(c)
39+
3940
# category - iopub data rate limit issue...
41+
cInfo['category']= []
4042
ifstr(df[c].dtype)=='object':
4143
uniqValues=df[c].dropna().unique()
4244
iflen(uniqValues)<=20:
4345
cInfo['category']= [{"value":"'{}'".format(u)iftype(u)==strelseu,"label":u }foruinuniqValues]
44-
else:
45-
cInfo['category']= []
46-
else:
47-
cInfo['category']= []
46+
4847
colList.append(cInfo)
4948
returncolList
5049

‎python/userCommand.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importfitz
1111
importnltk
1212
nltk.download('punkt')
13+
1314
######
1415
# Visual Python: Data Analysis > PDF
1516
######
@@ -43,6 +44,7 @@ def vp_pdf_get_sentence(fname_lst):
4344
df=_vp_pd.concat([df,df_doc])
4445

4546
returndf.reset_index().drop('index',axis=1)
47+
4648
######
4749
# Visual Python: Data Analysis > Frame
4850
######
@@ -63,6 +65,7 @@ def vp_drop_outlier(df, col, weight=1.5):
6365
df_res=df.drop(outlier_index).copy()
6466

6567
returndf_res
68+
6669
######
6770
# Visual Python: Machine Learning > Model Info
6871
######
@@ -74,10 +77,12 @@ def vp_create_feature_importances(model, X_train=None, sort=False):
7477

7578
df_i=_vp_pd.DataFrame(model.feature_importances_,index=feature_names,columns=['Feature_importance'])
7679
df_i['Percentage']=100* (df_i['Feature_importance']/df_i['Feature_importance'].max())
77-
ifsort:df_i.sort_values(by='Feature_importance',ascending=False,inplace=True)
80+
ifsort:
81+
df_i.sort_values(by='Feature_importance',ascending=False,inplace=True)
7882
df_i=df_i.round(2)
7983

8084
returndf_i
85+
8186
######
8287
# Visual Python: Machine Learning > Model Info
8388
######
@@ -91,10 +96,13 @@ def vp_plot_feature_importances(model, X_train=None, sort=False, top_count=0):
9196
df_i['Percentage'].sort_values().plot(kind='barh')
9297
else:
9398
df_i['Percentage'].plot(kind='barh')
99+
94100
_vp_plt.xlabel('Feature importance Percentage')
95101
_vp_plt.ylabel('Features')
96-
97102
_vp_plt.show()
103+
104+
return
105+
98106
######
99107
# Visual Python: Visualization > Seaborn
100108
######
@@ -134,4 +142,6 @@ def _single(ax):
134142
foridx,axin_vp_np.ndenumerate(axs):
135143
_single(ax)
136144
else:
137-
_single(axs)
145+
_single(axs)
146+
147+
return

‎python/variableCommand.py‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
importnumpyas_vp_np
2+
importrandomas_vp_rd
13
"""
24
Search Variables
35
"""
@@ -77,8 +79,6 @@ def _vp_get_profiling_list():
7779

7880
returnresult
7981

80-
importnumpyas_vp_np
81-
importrandomas_vp_rd
8282
def_vp_sample(data,sample_cnt):
8383
"""
8484
Sampling data
@@ -94,16 +94,13 @@ def _vp_sample(data, sample_cnt):
9494
returndata[_vp_np.random.choice(data.shape[0],sample_cnt,replace=False)]
9595
elifdataType=='list':
9696
return_vp_rd.choices(data,k=sample_cnt)
97+
9798
returndata
9899

99100
def_vp_check_module_loaded(fname_list):
100101
"""
101102
Check if this module is loaded
102103
"""
103-
result= []
104-
forfnameinfname_list:
105-
iffnameinglobals():
106-
result.append(True)
107-
else:
108-
result.append(False)
104+
result= [Trueiffnameinglobals()elseFalseforfnameinfname_list]
105+
109106
returnresult

‎python/visualizationCommand.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ def _vp_seaborn_show_values(axs, precision=1, space=0.01):
77
pstr='{:.'+str(precision)+'f}'
88

99
def_single(ax):
10-
# check orient
10+
# check orient / if 0
1111
orient='v'
12-
iflen(ax.patches)==1:
13-
# check if 0
14-
ifax.patches[0].get_x()==0:
15-
orient='h'
12+
iflen(ax.patches)==1andax.patches[0].get_x()==0:
13+
orient='h'
1614
else:
1715
# compare 0, 1 patches
1816
p0=ax.patches[0]
@@ -36,7 +34,7 @@ def _single(ax):
3634
ax.text(_x,_y,value,ha='left')
3735

3836
ifisinstance(axs,_vp_np.ndarray):
39-
foridx,axin_vp_np.ndenumerate(axs):
37+
for_,axin_vp_np.ndenumerate(axs):
4038
_single(ax)
4139
else:
4240
_single(axs)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp