Python数据挖掘2:pandas使用:Series一串数字和DataFrame数据框
生活随笔
收集整理的這篇文章主要介紹了
Python数据挖掘2:pandas使用:Series一串数字和DataFrame数据框
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
'''
pandas
來源:Dust的天善智能韋瑋老師 課堂筆記
'''
import pandas as pda
'''
Series 一串?dāng)?shù)字
index 索引,默認(rèn)0,1,2,3
DataFrame 數(shù)據(jù)框
'''
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]]) # 數(shù)組默認(rèn)從0開始編號(hào)
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, # 會(huì)自動(dòng)填充成4,4,4
"two":[6,2,3],
"three":list(str(982)) # 直接用list
})
print(e)#d.head(行數(shù)) 調(diào)取數(shù)據(jù)框里的頭部數(shù)據(jù),默認(rèn)前五行,如果不夠就全部取完
print("---head---")
print(d.head())
print("---head2---")
print(d.head(2))
#d.tail(行數(shù)) 取末尾數(shù)據(jù),默認(rèn)五行。
print("---tail2---")
print(d.tail(2))#d.describe() 統(tǒng)計(jì)數(shù)據(jù)情況
print("---describe---")
print(d.describe())
'''
count 個(gè)數(shù)
mean 平均數(shù)
std 標(biāo)準(zhǔn)差
min 一列中所有數(shù)的最小值
25% 前分位數(shù)
50% 中分位數(shù)
75% 后分位數(shù)
max 一列中的最大值
'''
# 轉(zhuǎn)置:行和列顛倒
print("---d.T---")
print(d.T)
總結(jié)
以上是生活随笔為你收集整理的Python数据挖掘2:pandas使用:Series一串数字和DataFrame数据框的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代理记账会计一个月大约多少钱
- 下一篇: ‘utf-8‘ codec can‘t