pandas Series模块知识点

代码笔记:

 

# -*- coding: utf-8 -*-
# @Time  : 2/7/2022
# @Athor : WuHe
# @File  : pandasSeriesRecode.py

import pandas as pd


# s=pd.Series(data,index,dtype,copy)

def empty_series():
    s = pd.Series()
    print('1.this is empty Series:')
    print(s)
    '''
    Series([], dtype: float64)
    '''


def create_series():
    s = pd.Series([1, 2, 3, 4, 5, 6, 7], index=['a', 'b', 'c', 'd', 'e', 'f', 'g', ])
    print('2.this is a create Series:')
    print(s)
    '''
    a    1
    b    2
    c    3
    d    4
    e    5
    f    6
    g    7
    dtype: int64
    '''

    print('3.this is section切片【0-3】 read:')
    print(s[:3])
    '''
    a    1
    b    2
    c    3
    dtype: int64
    '''

    print('4.return all index:')
    print(s.axes)
    '''
    [Index(['a', 'b', 'c', 'd', 'e', 'f', 'g'], dtype='object')]
    '''

    print('5.查看对象是否为空:')
    print(s.empty)
    '''
    False
    '''

    print('6.查看对象的维数,series始终是1维:')
    print(s.ndim)
    '''
    1
    '''

    print('7.查看对象长度:')
    print(s.size)
    '''
    7
    '''
    print('8.以数组方式查看serise:')
    print(s.values)
    '''
    [1 2 3 4 5 6 7]
    '''

    print('9.查看index的范围:')
    print(s.index)
    '''
    Index(['a', 'b', 'c', 'd', 'e', 'f', 'g'], dtype='object')
    '''

    print('10.查看前3行,缺省默认5行:')
    print(s.head(3))
    '''
    a    1
    b    2
    c    3
    dtype: int64
    '''

    print('11.查看后3行,缺省默认5行:')
    print(s.tail(3))
    '''
    e    5
    f    6
    g    7
    dtype: int64
    '''

    print('12.检测缺失项isnull,notnull结果相反:')
    print(pd.isnull(s))
    '''
    a    False
    b    False
    c    False
    d    False
    e    False
    f    False
    g    False
    dtype: bool
    '''


if __name__ == '__main__':
    empty_series()
    create_series()

 

posted @ 2022-02-07 15:53  再次路过之  阅读(30)  评论(0编辑  收藏  举报