美文网首页
3. 日月光华 Python数据分析-Pandas-Serie

3. 日月光华 Python数据分析-Pandas-Serie

作者: 薛东弗斯 | 来源:发表于2023-07-05 05:42 被阅读0次
import pandas as pd

s = pd.Series([1,3,6,2])
s
# 0    1
# 1    3
# 2    6
# 3    2
# dtype: int64

s.index
# RangeIndex(start=0, stop=4, step=1)

s.values
# array([1, 3, 6, 2], dtype=int64)

s1 = pd.Series([1,3,6,2], index=['a', 'b', 'c', 'd'])
s1
# a    1
# b    3
# c    6
# d    2
# dtype: int64

s.index
# Index(['a', 'b', 'c', 'd'], dtype='object')

s[s<3]
# a    1
# d    2
# dtype: int64

s*4
# a     4
# b    12
# c    24
# d     8
# dtype: int64
import numpy as np
np.mean(s)   # 3.0
s.mean()      # 3.0
s.max()        # 6
s.index        # Index(['a', 'b', 'c', 'd'], dtype='object')
'e' in s.index  # False
s = pd.Series({'a': 1, 'b': 9, 'c': 4})
s
# a    1
# b    9
# c    4
# dtype: int64
s = pd.Series({'a': 1, 'b': 9, 'c': 4}, index=['a', 'b', 'd'])
s
# a    1
# b    9
# d    NaN
# dtype: int64

s[s.isnull()]
#d   NaN
#dtype: float64

自动按照索引对齐

s
# a    1.0
# b    9.0
# d    NaN
# dtype: float64

s1
# a    1
# b    3
# c    6
# d    2
# dtype: int64

s + s1
# a     2.0
# b    12.0
# c     NaN
# d     NaN
# dtype: float64

s.notnull()
# a     True
# b     True
# d    False
# dtype: bool

s
# a    1.0
# b    9.0
# d    NaN
# dtype: float64

s['a']   
# 1.0

s[['a', 'b']]
# a    1.0
# b    9.0
# dtype: float64

s1
# a    1
# b    3
# c    6
# d    2
# dtype: int64

s1['a': 'c']
# a    1
# b    3
# c    6
# dtype: int64

s['a'] = 1000
s
# a    1000.0
# b       9.0
# d       NaN
# dtype: float64
s
# a    1000.0
# b       9.0
# d       NaN
# dtype: float64

s[s.isnull()]
# d   NaN
# dtype: float64

s[~s.isnull()]
# a    1000.0
# b       9.0
# dtype: float64

s[s.notnull()]
# a    1000.0
# b       9.0
# dtype: float64

取出一列,就是一个series

相关文章

  • Python数据分析——数据预处理的方法

    前言 1. 关于数据集 数据来源:日月光华老师的《Python数据分析从入门到机器学习》的 lianjia 数据。...

  • 链家数据分析二-数据分组处理

    关于  学习日月光华老师的《Python数据分析从入门到机器学习》,通过写该文来巩固数据分析中使用的知识点。主要是...

  • 链家数据--房子单价离散区间直方图展示

    关于学习日月光华老师的《Python数据分析从入门到机器学习》,通过写该文来巩固数据分析中使用的知识点。主要是针对...

  • 某网价值1800元的Python课程分享

    1. Python3数据分析与挖掘建模实战(全) 2. Python3数据科学入门与实战 3. Python前后端...

  • (九)数据的学习|python数据分析与展示(学习笔记)

    1.数据的排序2.数据的基本统计分析3.数据的累计统计分析4.数据的相关分析5.小结[网页链接【Python数据分...

  • 日月光华

    日月光华,旦复旦兮。 江河日下兮,望我八方; 先盛后衰兮,何类始皇; 时不利我兮,顺水流觞; 天灭我陈兮,且为之奈...

  • 日月光华

    晚间小诗 《卿云歌》 卿云烂兮,糺(jiū)缦缦兮。 日月光华,旦复旦兮。 明明上天,烂然星陈。 日月光华,弘于一人。

  • 机器学习书籍

    1.《利用python进行数据分析》 Wes McKinney著 唐学韬 2. 《python机器学习》 3. 《...

  • python电子书汇总

    Python金融大数据分析_雅格书林 Python数据分析与挖掘实战 Python核心编程(第3版) Python...

  • 2019数据科学三本书

    《python cookbook》 《python 核心编程》 《Python 数据分析》

网友评论

      本文标题:3. 日月光华 Python数据分析-Pandas-Serie

      本文链接:https://www.haomeiwen.com/subject/fdbcudtx.html