日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

ipython --pandas

發(fā)布時間:2023/11/27 生活经验 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ipython --pandas 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

d定義:

pandas是一個強大的Python數(shù)據(jù)分析的工具包。

pandas是基于NumPy構建的。

安裝方法:

pip install pandas

import pandas as pd

pandas的主要功能

具備對其功能的數(shù)據(jù)結構DataFrame、Series

集成時間序列功能

提供豐富的數(shù)學運算和操作

靈活處理缺失數(shù)據(jù)

?

Series

定義:Series是一種類似于一位數(shù)組的對象,由一組數(shù)據(jù)和一組與之相關的數(shù)據(jù)標簽(索引)組成。

創(chuàng)建方式:

創(chuàng)建方式:
pd.Series([4,7,-5,3]) 
pd.Series([4,7,-5,3],index=['a','b','c','d'])               
pd.Series({'a':1, 'b':2})             
pd.Series(0, index=['a','b','c','d’])

?

獲取值數(shù)組和索引數(shù)組:values屬性和index屬性

Series比較像列表(數(shù)組)和字典的結合體。

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

實例:

sr=pd.Series([1,2,3,4],index=['a','b','c','d'])sr['a':'c']==>
a   -4
b    3
c    5
dtype: int64sr[['a','d']]==
a   -4
d    6
dtype: int64判斷 條件是鍵不是值
'b' in sr
==
true1 in sr
==
flase取值: 取值的方法和字典相類似
sr.get('a',0)
判斷,切片,取值

?

sr=pd.Series([1,2,3,4],index=['b','c','d','a'])b    1
c    2
d    3
a    4
dtype: int64sr.iloc[1]   #取索引為1 
==
2sr.ilc[2]  #取索引為2
==
3
取索引

?

sr=pd.Series([1,2,3,4],index=['b','c','d','a'])
sr1=pd.Series([5,6,7,8,9],index=['a','b','c','d','e'])
sr2=pd.Series([5,6,7,8,9,10],index=['a','b','c','d','e','f'])sr+sr1
==
a     9.0
b     7.0
c     9.0
d    11.0
e     NaN
dtype: float64
PS:多出來的值只是NANadd方法
sr3=sr.add(sr2,fill_value=0)sr3:
==
a     9.0
b     7.0
c     9.0
d    11.0
e     9.0
f    10.0
dtype: float64用add方法:沒有就加上,不會出現(xiàn)Nan
add方法和 a+b區(qū)別
sr4a     9.0
b     7.0
c     9.0
d    11.0
e     NaN
dtype: float64sr4.notnull()
a     True
b     True
c     True
d     True
e    False
dtype: boolsr4[sr4.notnull()]  #把是NAN的去掉a     9.0
b     7.0
c     9.0
d    11.0sr4.dropna()  #也是直接去掉為nan的
a     9.0
b     7.0
c     9.0
d    11.0
dtype: float64
notnull()和dropna()

?

sr=pd.DataFrame({'one':[1,2,3,4],'two':[32,4,5,6]},index=['a','s','d','q'])
import random
li = [random.uniform(10,20) for _ in range(1000)]
ratio = 6.3list(map(lambda x:x*ratio, li))
map函數(shù)調用
df = pd.read_csv('601318.csv', header=None, names=list('asdfghjk'))

?

  

?

df = pd.read_csv('601318.csv',index_col=1, parse_dates=['date'])
df

?

?

?

?



df.groupby('key1').sum()

?

  

?

轉載于:https://www.cnblogs.com/52forjie/p/8379924.html

總結

以上是生活随笔為你收集整理的ipython --pandas的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。