大資料統計筆記

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   資料   2014   

# -*- coding: utf-8 -*-import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport jsons = pd.Series([1,3,5,np.nan,6,8]);print(s);s = pd.Series([1,3],["a","b"]);print(s);#迴圈查詢日期範圍內資料dates = pd.date_range(‘20130101‘,periods=6);print(dates);df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list(‘ABCD‘))print("LIMIT:============");print(df.head(3));print(df.tail(3));print("反轉XY顯示 :============");print(df.T);#排序#df.sort_index(axis=1, ascending=False)#df.sort(columns=‘B‘) ########################選取器#############################print("指定列 :============");print(df[[‘A‘,‘B‘]]);print("df[行範圍,列範圍]:============");print(df[0:3]);print("指定索引主鍵 :============");print(df[‘20130103‘:‘20130104‘]);print("布爾過濾 :============");print(df[df.A>0.5]);#print(df[0:3,0:1]);########################距陣操作 #############################print("距陣操作 :============");print(df*2);print(np.exp(df));########################TABLE 元素##############################以二維數組顯示#df.values#列描述#df.columns#索引#df.index #物件類型#df.dtypesprint("字典(JSON)轉換距陣 :============");sdata = {‘Ohio‘: 35000, ‘Texas‘: 71000, ‘Oregon‘: 16000, ‘Utah‘: 5000};df = pd.Series(sdata);print(df);sdata = [{‘Ohio‘: 35000, ‘Texas‘: 71000, ‘Oregon‘: 16000, ‘Utah‘: 5000}];df = pd.DataFrame(sdata);df.columns = [‘Ohio‘, ‘Texas‘, ‘Oregon‘, ‘Utah‘];print(df);df = df.fillna(0) #將缺失值都替換為0#入門#http://pandas.pydata.org/pandas-docs/stable/10min.html#http://pda.readthedocs.org/en/latest/chp5.html#blog#http://cloga.info/#wat_e_eb3d32d8-f59a-4a08-bf96-6f706d89c097_zss_#大資料#http://www.17bigdata.com/?cat=22#最佳化#http://1.aisensiy.sinaapp.com/2014/03/%E6%9C%80%E8%BF%91%E4%BD%BF%E7%94%A8-pandas-%E7%9A%84%E6%80%BB%E7%BB%93/df.to_csv(‘E:\\py\\foo.csv‘)######################JSON###########################print("josn====================");j = [{‘0‘:{"a":"a"},‘1‘:{"b":"b"}}];elevations = json.dumps(j);df = pd.read_json(elevations );print(df);

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.