import pandas as pd
import numpy as np
# pandas基本数据结构
# Series 一维数组,与numpy中的一维array相似,二者与pyhton列表也相近。Series能保存不同数据类型,字符串,boolean值,数字等都能保存在series中
# Dateframe 二维的表格型数据结构。很多功能与R中date.frame类似。可以将DateFrame理解为Series的容器。以下的内容主要以DateFrame为主
# Series
# 一维Series可以用一维列表初始化; 索引可以自己设置
s = pd.Series([1,2,3])
'''0 1
1 2
2 3
dtype: int64'''
s = pd.Series([1,2,4],index =['a','b','c'])
'''a 1
b 2
c 4
dtype: int64'''
# 当使用其他字符作为索引时,切片操作为双闭合,两边端点元素都要取
# 查看数据索引:行标签
s.index # Index(['a', 'b', 'c'], dtype='object')
s.values # array([1, 2, 4], dtype=int64)
# 索引赋值
s.index.name='索引'
'''索引
a 1
b 2
c 4
dtype: int64'''
s.index=list('012')
'''0 1
1 2
2 3
dtype:
Pandas两种数据类型(jupyter)
最新推荐文章于 2024-05-20 06:44:33 发布