Pandas: 1、基礎知識_Ceilometer

來源:互聯網
上載者:User
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time    : 4/14/18 11:17 AM# @Author  : Aries# @Site    : # @File    : main.py# @Software: PyCharm'''以下內容參考: 參考: https://www.cnblogs.com/misswangxing/p/7903595.htmlpandas入門:1 基礎知識pandas: 含義:python資料分析庫是基於NumPy的工具。縮寫:panel data,data analysis特點:1引入標準資料模型,提供處理資料的方法2為時間序列分析提供很好的支援資料結構:Series:一位元組,和Numpy中的一維array類似,與List類似區別:List中元素可以是不同資料類型,Array和Series只允許儲存相同資料類型Time-Series:以時間為索引的SeriesDataFrame:二維表格式資料結構,是Series的的容器Panel:三維數組,DataFrame容器Pandas定義的資料類型:Series和DataFrame安裝:pip install pandas2 Pandas使用3 SeriesSeries同列表一樣,一些列資料,每個資料對應一個索引值.Series是豎起來的list實質上建立了一個Series對象屬性顯示了Series的索引和資料值預設的Series索引實際上就是整數Series可以自訂索引(此時可以認為是一個字典)有索引的作用:根據索引操作元素定義Series的三種形式:1 列表形式,例如s = Series([1, 4, 'www', 'tt'])2 列表+索引形式,例如s2 = Series(['chao', 'man', '29'], index=['name', 'sex', 'age'])3 字典形式s4 = Series({'score':329, 'age':29})自訂索引:自定的索引會尋找原來的索引,如果一樣的就用原來的值代替沒有值:對齊賦給NaN判斷是否為空白:pandas.isnull(s4)s4.isnull()索引賦值:s4.index=['語文', '數學', 'English']尋找series中過濾條件後的元素result = s4[s4 > 300]4 DataFrame含義:二維的資料結構,類似試算表和mysql資料庫形式豎行:稱為columns橫行:和Series一樣,稱為index通過columns和index確定主句的位置定義: 定義一個DataFrame對象的方法,使用dict字典的鍵:name, marks, price是每一個維度名稱,就是columns的名稱鍵的值:是列表,這裡沒有設定索引,是走預設索引columns跟字典鍵相比,其順序可以被規定也就是列名的順序可以轉換DataFrame的索引也能夠自訂例子:data = {"name":['google', 'baidu', 'yahoo'],        "marks":[100,200,300],        "price":[1,2,3]}            f1 = DataFrame(data)f3 = DataFrame(data, columns=['name', 'marks', 'price'], index=['a', 'b', 'c'])字典嵌套字典定義另外一篇可以參考的文章:https://blog.csdn.net/qq_16234613/article/details/62046057官網:http://pandas.pydata.org/Time series-functionality: date range generation and frequency conversion, moving window statistics, moving window linear regressions, date shifting and lagging. Even create domain-specific time offsets and join time series without losing data;'''from pandas import Seriesfrom pandas import DataFrameimport pandas as pddef process():    s = Series([1, 4, 'www', 'tt'])    print s    print s.index    print s.values    s2 = Series(['chao', 'man', '29'], index=['name', 'sex', 'age'])    print s2    print s2['name']    s2['name'] = 'chen'    print s2    sd = {'score':329, 'age':29}    s3 = Series(sd)    print s3    s33 = Series({'score':329, 'age':29})    print s33    s4 = Series(sd, index=['java', 'score', 'age'])    print s4    print pd.isnull(s4)    print s4.isnull()    s4.index = ['語文', '數學', 'English']    print s4    s44 = s4 * 2    print s44    result = s4[s4 > 300]    print result    print type(result)def processDataFrame():    data = {"name":['google', 'baidu', 'yahoo'],            "marks":[100,200,300],            "price":[1,2,3]}    f1 = DataFrame(data)    print f1    f2 = DataFrame(data, columns=['name', 'price', 'marks'])    print f2    f3 = DataFrame(data, columns=['name', 'marks', 'price'], index=['a', 'b', 'c'])    print f3    print f3['name']    newData = {"lang":{'first':'python', 'second':'java'}, 'price':{'first':5000, 'second':2000}}    f4 = DataFrame(newData)    print f4if __name__ == "__main__":    # process()    processDataFrame()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.