1. 程式人生 > >【Pandas + Matplotlib】初體驗:讀取資料檔案 + 繪製資料散點圖

【Pandas + Matplotlib】初體驗:讀取資料檔案 + 繪製資料散點圖

Pandas :納入大量庫和一些標準資料模型,是一款高效的資料處理工具。

Matplotlib:Python中最常用的視覺化工具之一,可以非常方便地建立海量型別地2D圖表和一些基本的3D圖表。

下面我自己建立的一個Excel檔案,利用Pandas來讀取資料,Matplot來顯示資料圖。

資料檔案如下:


程式碼:

import pandas as pd
import matplotlib.pyplot as  plt

def main():
    df = pd.read_excel("mytest.xlsx")
    
    height = df['身高']
    weight = df['體重']
    
    print("資料行數:" , len(df))
    
    #設定 x ,y 軸的取值範圍
    plt.scatter(height,weight)
    #標籤
    plt.title('身高體重圖')
    plt.xlabel("Height")
    plt.ylabel("Weight")
    plt.show()
    
if __name__ == '__main__':
    main()

結果顯示:


為什麼title不能顯示為漢字?

--matplot 預設不顯示漢字,如需處理請搜尋相關教程