課堂老師提供的學習方式:
閱讀官方API文件,以及查看資料型態以及方法
舉例:
台灣行列用語與大陸用法不同
查看網路資料須留意
直行橫列
(前列,後行)
隨筆記錄區:
pandas 最強函式: apply
numpy 的小孩:pandas
獲得資料後讀取,產生一維或二維資料
資料格式:
Pandas 專屬資料型態認識
學習如何新增/修改/刪除/排序/索引/切片
額外學習如何處理日期資料,
what is
列索引物件
行索印物件
最後將整理好的資料視覺化
可以使用的工具:
步驟:讀取檔案,轉成 pandas 可讀取形式,修改欄位名稱,查看資料型態
產生 DataFrames 的方式
字典 key 當行索引
或是多組列資料,指定行列索引
第一種查看方式:
使用字典建立 Series
使用字典建立 Series 時,字典的鍵成為索引,值成為數據。
官方提供的案例:
output :
第二種查看方式:
將資料轉成 dataframe 後
df.dtypes
會回傳一個 Series
裡面儲存每個欄位的資料型態
參考資料:
https://medium.com/@hui509/pandas-新增-series-或-dataframe-bb41c4098603
https://pandas.pydata.org/docs/reference/api/pandas.concat.html#pandas.concat
要注意 series 是 一維
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.astype.html#pandas.DataFrame.astype
用 df.info()
查看表格結構
備註:他會回傳一個新的,要重新賦予
df["欄位"] = list(range(1,10))
df.loc["索引"] = list(range(1,10))
其中要特別注意的是
Dataframe:
新增 col 直行:
df.loc[:,'直行'] 可以縮寫成 df['直行']
新增 row 橫行:
df.loc[1000] 不可以縮寫
x 沒記錄到
用文字或是位置當作索引,選取位置
.loc["行的索引值"]
老師說明要區分是處理 series 還是 dataframe
網路上都在教 dataframe 的例子
下列是使用 Series 的 round 函式 (dataframe一樣有)
series rank
用在排名,ascending=False
dataframe rank
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rank.html#pandas.DataFrame.rank
https://pandas.pydata.org/docs/reference/api/pandas.Series.str.strip.html#pandas.Series.str.strip
時間轉字串
str from time
Function is not implemented. Use pd.to_datetime().
str phase time
民國年要改成西元年
使用 apply 函式,去寫自定義 func
pandas 有 timestamp 物件
https://timestamp.onlinealat.com
https://pandas.pydata.org/docs/reference/api/pandas.Timestamp.year.html
pandas series 有 year / month / day https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.year.html#
https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html#pandas-to-datetime
直行 columns
橫列 index
與前面一維 Series 互相比較
(未騰入筆記)
(大部分都是)用 dataframe 舉例的教學:
https://ithelp.ithome.com.tw/articles/10343746
用實際案例舉例如何操作,製圖讚讚,一系列資料科學相關文章
https://medium.com/ntu-data-analytics-club/python-advanced-一起來用-pandas-玩轉數據-6d06d805941a
Day10Learning Pandas - Series、DataFrame、Index
https://ithelp.ithome.com.tw/articles/10204656
智能股市分析師:Python股價歷史資料自動化爬蟲與分析
https://hackmd.io/@Tj7zBL4CS-CymiaJeR8Uew/SkZ8TFvB6