Python数据挖掘2:pandas使用:Series一串数字和DataFrame数据框
生活随笔
收集整理的這篇文章主要介紹了
Python数据挖掘2:pandas使用:Series一串数字和DataFrame数据框
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
'''
pandas
來源:Dust的天善智能韋瑋老師 課堂筆記
'''
import pandas as pda
'''
Series 一串數字
index 索引,默認0,1,2,3
DataFrame 數據框
'''
a=pda.Series([8,9,2,1])
print(a)
b=pda.Series([8,9,2,1],index=["one","two","three","four"])
print(b)
c=pda.DataFrame([[1,2,3],[4,5,6],[7,8,9]]) # 數組默認從0開始編號
print(c)
d=pda.DataFrame([[1,2,3],[4,5,6],[7,8,9]],columns=["one","two","three"]) # 指定列名
print(d)
e=pda.DataFrame({ # 第一列,第二列,第三列
"one":4, # 會自動填充成4,4,4
"two":[6,2,3],
"three":list(str(982)) # 直接用list
})
print(e)#d.head(行數) 調取數據框里的頭部數據,默認前五行,如果不夠就全部取完
print("---head---")
print(d.head())
print("---head2---")
print(d.head(2))
#d.tail(行數) 取末尾數據,默認五行。
print("---tail2---")
print(d.tail(2))#d.describe() 統計數據情況
print("---describe---")
print(d.describe())
'''
count 個數
mean 平均數
std 標準差
min 一列中所有數的最小值
25% 前分位數
50% 中分位數
75% 后分位數
max 一列中的最大值
'''
# 轉置:行和列顛倒
print("---d.T---")
print(d.T)
總結
以上是生活随笔為你收集整理的Python数据挖掘2:pandas使用:Series一串数字和DataFrame数据框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代理记账会计一个月大约多少钱
- 下一篇: 一台加工中心多少钱啊?