Python中的Series模块学习

Python中的Series模块学习

本文是基于Windows系统环境,学习和测试Series模块:

  • Windows 10

  • PyCharm 2018.3.5 for Windows (exe)

  • python 3.6.8 Windows x86 executable installer


1. 增改删查

  • 初始化一个Series
from pandas import Series
info = Series([13, 'rose', True], index=['age', 'name', 'isStudent'])
info1 = Series([13, 'rose', True])
print(info)
print(info1)
  • 向Series插入一个元素
from pandas import Series
info = Series([13, 'rose', True], index=['age', 'name', 'isStudent'])
print(info)
info = info.append(Series(['female'],index=['gender']))
info1 = info.append(Series(['female']))
print(info)
  • 删除Series的一个元素
from pandas import Series
info = Series([13, 'rose', True], index=['age', 'name', 'isStudent'])
print(info)
info.drop('name')
print(info)
  • 查询值不为某个特定值的元素
from pandas import Series
info = Series([13, 'rose', True], index=['age', 'name', 'isStudent'])
print(info)
info1 = info[13 != info.values]
info2 = info['rose' != info.values]
info3 = info[True != info.values]
print(info1)
print(info2)
print(info3)

2. 遍历

  • 遍历所有的的索引和索引值
from pandas import Series
info = Series([13, 'rose', True], index=['age', 'name', 'isStudent'])
print(info)
for index in info.index:
    print(index, '=', info[index])

参考文献

你可能感兴趣的:(Python)