<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
Pandas模組的資料結構主要有兩種:1.Series 2.DataFrame
Series 是一維陣列,基於Numpy的ndarray 結構
Series([data, index, dtype, name, copy, …]) # One-dimensional ndarray with axis labels (including time series).
import Pandas as pd import numpy as np
引數為list ,index為可選引數,若不填寫則預設為index從0開始
obj = pd.Series([4, 7, -5, 3, 7, np.nan]) obj
輸出結果為:
0 4.0
1 7.0
2 -5.0
3 3.0
4 7.0
5 NaN
dtype: float64
arr = np.arange(6) s = pd.Series(arr) s
輸出結果為:
0 0
1 1
2 2
3 3
4 4
5 5
dtype: int32
pd.Series({dict}) d = {'a':10,'b':20,'c':30,'d':40,'e':50} s = pd.Series(d) s
輸出結果為:
a 10
b 20
c 30
d 40
e 50
dtype: int64
可以通過DataFrame中某一行或者某一列建立序列
obj.values # array([ 4., 7., -5., 3., 7., nan])
obj.index # RangeIndex(start=0, stop=6, step=1)
Series.value_counts:Return a Series containing counts of unique values.
index = ['Bob', 'Steve', 'Jeff', 'Ryan', 'Jeff', 'Ryan'] obj = pd.Series([4, 7, -5, 3, 7, np.nan],index = index) obj.value_counts()
輸出結果為:
7.0 2
3.0 1
-5.0 1
4.0 1
dtype: int64
Series.sort_values
Series.sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')
Parameters:
Parameters | Description |
---|---|
axis | {0 or ‘index’}, default 0,Axis to direct sorting. The value ‘index’ is accepted for compatibility with DataFrame.sort_values. |
ascendin | bool, default True,If True, sort values in ascending order, otherwise descending. |
inplace | bool, default FalseIf True, perform operation in-place. |
kind | {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’Choice of sorting algorithm. See also numpy.sort() for more information. ‘mergesort’ is the only stable algorithm. |
na_position | {‘first’ or ‘last’}, default ‘last’,Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end. |
Returns:
Series:Series ordered by values.
obj.sort_values()
輸出結果為:
Jeff -5.0
Ryan 3.0
Bob 4.0
Steve 7.0
Jeff 7.0
Ryan NaN
dtype: float64
Series.rank(self, axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)[source]
Parameters:
Parameters | Description |
---|---|
axis | {0 or ‘index’, 1 or ‘columns’}, default 0Index to direct ranking. |
method | {‘average’, ‘min’, ‘max’, ‘first’, ‘dense’}, default ‘average’How to rank the group of records that have the same value (i.e. ties): average, average rank of the group; min: lowest rank in the group; max: highest rank in the group; first: ranks assigned in order they appear in the array; dense: like ‘min’, but rank always increases by 1,between groups |
numeric_only | bool, optional,For DataFrame objects, rank only numeric columns if set to True. |
na_option | {‘keep’, ‘top’, ‘bottom’}, default ‘keep’, How to rank NaN values:;keep: assign NaN rank to NaN values; top: assign smallest rank to NaN values if ascending; bottom: assign highest rank to NaN values if ascending |
ascending | bool, default True Whether or not the elements should be ranked in ascending order. |
pct | bool, default False Whether or not to display the returned rankings in percentile form. |
Returns:
same type as caller :Return a Series or DataFrame with data ranks as values.
# obj.rank() #從大到小排,NaN還是NaN obj.rank(method='dense') # obj.rank(method='min') # obj.rank(method='max') # obj.rank(method='first') # obj.rank(method='dense')
輸出結果為:
Bob 3.0
Steve 4.0
Jeff 1.0
Ryan 2.0
Jeff 4.0
Ryan NaN
dtype: float64
到此這篇關於Python資料處理之pd.Series()函數的基本使用的文章就介紹到這了,更多相關Python pd.Series()函數內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45