甘肃快3

专业网站建设B/S软件开发专业微信营销专业技术建设团队做客户满意度最高的软件公司
漯河网站建设、漯河网站开发
 

7个Python特殊技巧,助力你的数据分析工作之路

作者:网站建设出处:京创科技发布时间:2019年11月06日点击数:75

甘肃快3 BENWENLIEJULEYIXIETISHENGHUOJIASURICHANGSHUJUFENXIGONGZUODEJIQIAO,BAOKUO:

1. Pandas Profiling

2. SHIYONG Cufflinks HE Plotly HUIZHI Pandas SHUJU

甘肃快3 3. IPython MOSHUMINGLING

甘肃快3 4. Jupyter ZHONGDEGESHIBIANPAI

5. Jupyter KUAIJIEJIAN

6. ZAI Jupyter(HUO IPython)ZHONGSHIYIGEDANYUANTONGSHIYOUDUOGESHUCHU

7. WEI Jupyter Notebook JISHICHUANGJIANHUANDENGPIAN

1. Pandas Profiling

GAIGONGJUXIAOGUOMINGXIAN。XIATUZHANSHILEDIAOYONG df.profile_report() ZHEIYIJIANDANFANGFADEJIEGUO:

SHIYONGGAIGONGJUZHIXUANZHUANGHEDAORU Pandas Profiling BAO。

BENWENBUZAIXIANGSHUZHEIYIGONGJU,RUYULEJIEGENGDUO,QINGYUEDU:

https://towardsdatascience.com/exploring-your-data-with-just-1-line-of-python-4b35ce21a82d

2. 使用 Cufflinks 和 Plotly 绘制 Pandas 数据

「JINGYANFENGFUDE」SHUJUKEXUEJIAHUOSHUJUFENXISHIDADUODUI matplotlib HE pandas HENSHUXI。YEJIUSHISHUO,NIZHIXUDIAOYONG .plot() FANGFA,JIKEKUAISUHUIZHIJIANDANDE pd.DataFrame HUO pd.Series:

YOUDIANWULIAO?

甘肃快3 ZHEIYIJINGHENHAOLE,BUGUOSHIFOUKEYIHUIZHIYIGEJIAOHUSHI、KESUOFANG、KEKUOZHANDEQUANJINGTUNI?SHISHIHOURANG Cufflinks* *CHUMALE!(Cufflinks JIYU Plotly ZUOLEJINYIBUDEBAOZHUANG。)

甘肃快3 ZAIHUANJINGZHONGANZHUANG Cufflinks,ZHIXUZAIZHONGDUANZHONGYUNXING! pip install cufflinks --upgrade JIKE。CHAKANXIATU:

XIAOGUOHAODUOLE!

ZHUYI,SHANGTUWEIYIGAIBIANDESHI Cufflinks cf.go_offline() DEDAORUHESHEZHI,TAJIANG .plot() FANGFABIANWEI .iplot()。

甘肃快3 QITAFANGFARU .scatter_matrix() YEKEYITIGONGFEICHANGBANGDEKESHIHUAJIEGUO:

甘肃快3 XUYAOZUODALIANGSHUJUKESHIHUAGONGZUODEPENGYOU,KEYIYUEDU Cufflinks HE Plotly DEWENDANG,FAXIANGENGDUOFANGFA。

  • Cufflinks WENDANG:https://plot.ly/ipython-notebooks/cufflinks/

  • Plotly WENDANG:https://plot.ly/

3. IPython 魔术命令

IPython DE「MOSHU」SHI IPython JIYU Python BIAOZHUNYUFADEYIXILIETISHENG。MOSHUMINGLINGBAOKUOLIANGZHONGFANGFA:XINGMOSHUMINGLING(line magics):YI % WEIQIANZHUI,ZAIDANGESHURUXINGSHANGYUNXING;DANYUANGEMOSHUMINGLING(cell magics):YI %% WEIQIANZHUI,ZAIDUOGESHURUXINGSHANGYUNXING。XIAMIANLIEJULE IPython MOSHUMINGLINGTIGONGDEYIXIEYOUYONGGONGNENG:

%lsmagic:找出全部命令

甘肃快3 RUGUONIZHIJIDEYIGEMOSHUMINGLING,NEIBIXUDESHIZHEIYIGE。ZHIXING %lsmagic MINGLINGJIANGTIGONGSUOYOUKEYONGMOSHUMINGLINGDELIEBIAO:

%debug:交互式 debug

ZHEIKENENGSHIWOZUICHANGSHIYONGDEMOSHUMINGLINGLE。

DABUFENSHUJUKEXUEJIADOUYUDAOGUOZHEIZHONGQINGKUANG:ZHIXINGDEDAIMAKUAIYIZHI break,NIWUWANGDIXIELE 20 GE print() YUJU,XIANGSHUCHUMEIGEBIANLIANGDENEIRONG。RANHOU,DANGNIZUIZHONGXIUFUWENTIHOU,NIHAIDEFANHUIBINGZAICISHANCHUSUOYOU print() YUJU。

BUGUOYIHOUZAIYEBUYONGZHEIYANGLE。YUDAOWENTIHOUZHIXUZHIXING %debug MINGLING,JIKEZHIXINGXIANGYAOYUNXINGDERENYIDAIMABUFEN:

SHANGTUZHONGFASHENGLESHENME?

  1. WOMENYOUYIGEHANSHU,TAYILIEBIAOWEISHURU,BINGDUISUOYOUDEOUSHUQUPINGFANGZHI。

  2. 甘肃快3 WOMENYUNXINGHANSHU,DANSHICHULEXIEWENTI。DANSHIWOMENBINGBUZHIDAOZENMEHUISHI!

  3. 甘肃快3 DUIGAIHANSHUSHIYONG%debug MINGLING。

  4. 甘肃快3 RANGDIAOSHIQIGAOSUWOMEN x HE type(x) DEZHI。

  5. WENTIXIANERYIJIAN:WOMENBA'6'ZUOWEIZIFUCHUANSHURUDAOHANSHUZHONGLE!

甘肃快3 ZHEIDUIYUGENGFUZADEHANSHUFEICHANGYOUYONG。

%store:在 notebook 之间传递变量

ZHEIGEMINGLINGYEHENKU。JIASHENIHUALEYIXIESHIJIANQINGXI notebook ZHONGDESHUJU,XIANZAINIXIANGZAILINGYIGE notebook ZHONGCESHIYIXIEGONGNENG,NEIMENISHIZAITONGYIGE notebook ZHONGSHIXIANGAIGONGNENG,HAISHIBAOCUNSHUJUBINGZAILINGYIGE notebook ZHONGJIAZAISHUJUNI?SHIYONG%store MINGLINGHOU,ZHEIXIECAOZUODOUBUXUYAO!GAIMINGLINGJIANGCUNCHUBIANLIANG,NIKEYIZAIQITARENYI notebook ZHONGJIANSUOGAIBIANLIANG:

  • %store [variable] CUNCHUBIANLIANG。

  • 甘肃快3 %store -r [variable] DUQU/JIANSUOCUNCHUBIANLIANG。

%who:列出所有全局变量。

NISHIFOUYUDAOGUO,WEIBIANLIANGFUZHIHOUQUEWANGJIBIANLIANGMINGDEQINGKUANG?HUOZHEBUXIAOXINSHANDIAOLEFUZEWEIBIANLIANGFUZHIDEDANYUANGE?SHIYONG%who MINGLING,NIKEYIDEDAOSUOYOUQUANJUBIANLIANGDELIEBIAO:

%%time:计时魔法命令

甘肃快3 SHIYONGGAIMINGLINGKEYILIEQU SUOYOUJISHIXINXI。ZHIXUDUIRENYIKEZHIXINGDAIMAYINGYONG%%time MINGLING,NIJIUKEYIDEDAORUXIASHUCHU:

%%writefile:向文件写入单元格内容

ZAI notebook ZHONGXIEFUZAHANSHUHUOLEI,QIEXIANGJIANGQIBAOCUNDAOZHUANSHUWENJIANZHONGSHI,GAIMOFAMINGLINGFEICHANGYOUYONG。ZHIXUWEIHANSHUHUOLEIDEDANYUANGETIANJIA %%writefile QIANZHUIHEXIANGYAOBAOCUNDAODEWENJIANMINGJIKE:

RUSHANGSUOSHI,WOMENKEYIJIANGCHUANGJIANDEHANSHUBAOCUNDAO utils.py WENJIANZHONG,RANHOUJIUKEYISUIYIDAORULE。ZAIQITA notebook ZHONGYEKEYIZHEIYANG,ZHIYAOYU utils.py WENJIANSHUYUTONGYIGEMULUJIKE。

4. Jupyter 中的格式编排

甘肃快3 ZHEIGEGONGJUHENKU!Jupyter KAOLVDAO markdown ZHONGCUNZAI HTML / CSS GESHI。YIXIASHIWOZUIJINGCHANGSHIYONGDEGONGNENG:

LANSE、SHISHANG:

<div class="alert alert-block alert-info">   This is <b>fancy</b>!</div>

甘肃快3 HONGSE、QINGWEIHUANGZHANG:

<div class="alert alert-block alert-danger"> This is <b>baaaaad</b>!</div>

LVSE、PINGJING:

<div class="alert alert-block alert-success"> This is <b>gooood</b>!</div>

XIATUZHANSHILETAMENDEYUNXINGGUOCHENG:

DANGNIXIANGYI Notebook GESHICHENGXIANYIXIEFAXIANSHI,ZHEIFEICHANGYOUYONG!

5. Jupyter 快捷键

XIANGLEJIEHEXUEXIJIANPANKUAIJIEJIAN,NIKEYISHIYONGMINGLINGMIANBAN:Ctrl + Shift + P,LIEQU notebook SUOYOUGONGNENGDELIEBIAO。XIAMIANXUANQULEJIGEZUIJICHUDEMINGLING:

  • Esc:JINRUMINGLINGMOSHI。ZAIMINGLINGMOSHINEI,NIKEYISHIYONGFANGXIANGJIANZAI notebook NEIJINXINGDAOHANG。

ZAIMINGLINGMOSHINEI:

  • A HE B:ZAIDANGQIANDANYUANGESHANGFANG(Above)HUOXIAFANG(Below)CHARUXINDEDANYUANGE。

  • 甘肃快3 M:DANGQIANDANYUANGEZHUANRU Markdown ZHUANGTAI。

  • 甘肃快3 Y:DANGQIANDANYUANGEZHUANRU code ZHUANGTAI。

  • D,D:SHANCHUDANGQIANDANYUANGE。

  • 甘肃快3 Enter:DANGQIANDANYUANGEHUIDAOBIANJIMOSHI。


甘肃快3 ZAIBIANJIMOSHINEI:

  • 甘肃快3 Shift + Tab:WEINIZAIDANGQIANDANYUANGEZHONGJIANRUDEDUIXIANGTIGONGWENDANGZIFUCHUAN(WENDANG),CHIXUSHIYONGGAIKUAIJIEJIAN,KEXUNHUANSHIYONGWENDANGMOSHI。

  • Ctrl + Shift + -:ZAIGUANGBIAOSUOZAICHUFENGEDANGQIANDANYUANGE。

  • Esc + F:CHAZHAOBINGTIHUANDAIMA(BUBAOKUOSHUCHU)。

  • Esc + O:QIEHUANDANYUANGESHUCHU。

XUANZEDUOGEDANYUANGE:

  • Shift + Down HE Shift + Up:XUANZHONGXIAFANGHUOSHANGFANGDEDANYUANGE。

  • Shift + M:HEBINGXUANZHONGDANYUANGE。

ZHUYI,XUANZHONGDUOGEDANYUANGEHOU,NIKEYIPILIANGZHIXINGSHANCHU/FUZHI/JIANQIE/ZHANTIE/YUNXINGCAOZUO。

6. 在 Jupyter(或 IPython)中使一个单元同时有多个输出

XIANGZHANSHI pandas DataFrame DE .head() HE .tail(),DANYOUYUCHUANGJIANYUNXING .tail() FANGFADEEWAIDAIMADANYUANGUOYUMAFANERBUDEBUZHONGTUFANGQI,NISHIFOUYOUGUOZHEIYANGDEJINGLI?XIANZAIBUYONGPALE,NIKEYISHIYONGYIXIADAIMAXINGZHANSHINIXIANGZHANSHIDESHUCHU:

from IPython.core.interactiveshell import InteractiveShellInteractiveShell.ast_node_interactivity = "all"

XIATUZHANXIANLEDUOGESHUCHUDEJIEGUO:

7. 为 Jupyter Notebook 即时创建幻灯片

SHIYONG RISE,NIKEYIJINTONGGUOYICIANJIANJIANG Jupyter Notebook JISHIZHUANBIANWEIHUANDENGPIAN。ERQIE notebook RENGRANCHUYUHUOYUEZHUANGTAI,NIKEYIZAIZHANSHIHUANDENGPIANDETONGSHIZHIXINGSHISHIBIANMA!

YAOXIANGSHIYONGGAIGONGJU,NIZHIXUTONGGUO conda HUO pip ANZHUANG RISE JIKE。

conda install -c conda-forge rise

HUOZHE

pip install RISE

甘肃快3 XIANZAI,NIKEYIDIANJIXINANNIU,WEI notebook CHUANGJIANBUCUODEHUANDENGPIANLE:

沙澧街