pandas数据操作
来源:互联网 发布:android图案解锁源码 编辑:程序博客网 时间:2024/06/18 13:46
pandas数据操作
字符串方法
Series对象在其str属性中配备了一组字符串处理方法,可以很容易的应用到数组中的每个元素
import numpy as npimport pandas as pdt = pd.Series(['a_b_c_d','c_d_e',np.nan,'f_g_h'])t
0 a_b_c_d1 c_d_e2 NaN3 f_g_hdtype: object
t.str.cat(['A','B','C','D'],sep=',') # 拼接字符串
0 a_b_c_d,A1 c_d_e,B2 NaN3 f_g_h,Ddtype: object
t.str.split('_') # 切分字符串
0 [a, b, c, d]1 [c, d, e]2 NaN3 [f, g, h]dtype: object
t.str.get(0) # 获取指定位置的字符串
0 a1 c2 NaN3 fdtype: object
t.str.replace("_", ".") # 替换字符串
0 a.b.c.d1 c.d.e2 NaN3 f.g.hdtype: object
t.str.pad(10, fillchar="?") # 左补齐
0 ???a_b_c_d1 ?????c_d_e2 NaN3 ?????f_g_hdtype: object
t.str.pad(10, side="right", fillchar="?") # 右补齐
0 a_b_c_d???1 c_d_e?????2 NaN3 f_g_h?????dtype: object
t.str.center(10, fillchar="?") #中间补齐
0 ?a_b_c_d??1 ??c_d_e???2 NaN3 ??f_g_h???dtype: object
t.str.find('d') # 查找给定字符串的位置,左边开始
0 6.01 2.02 NaN3 -1.0dtype: float64
t.str.rfind('d') # 查找给定字符串的位置,右边开始
0 6.01 2.02 NaN3 -1.0dtype: float64
数据转置(行列转换)
dates = pd.date_range('20130101',periods=10)dates
DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09', '2013-01-10'], dtype='datetime64[ns]', freq='D')
df = pd.DataFrame(np.random.randn(10,4),index=dates,columns=['A','B','C','D'])df.head()
df.head().T # 行列转换
对数据应用function
df.head().apply(np.cumsum) # cumsum 累加
频率
计算值出现的次数,类似直方图
s = pd.Series(np.random.randint(0, 7, size=10))s
0 31 32 13 64 35 36 57 28 19 0dtype: int32
s.value_counts()
3 41 26 15 12 10 1dtype: int64
阅读全文
0 0
- Pandas数据操作
- Pandas数据基本操作
- pandas数据操作
- Python 数据分析:pandas 操作基础篇
- Python数据分析库pandas基本操作
- python数据分析:pandas数据结构与操作
- python数据挖掘包Pandas基本操作
- pandas数据分组和聚合操作
- Python pandas库 数据切片 行列操作
- pandas操作
- 利用Pandas进行数据分析(2)——pandas数据基本操作
- python—pandas中DataFrame类型数据操作函数
- pandas做数据分析(三):常用预处理操作
- Python-Pandas 学习 数据中对时间的操作
- pandas数据预处理之dataframe的groupby操作
- python—pandas中DataFrame类型数据操作函数
- Pandas:时间序列数据基本操作和分组
- python—pandas中DataFrame类型数据操作函数
- C++基础---string类和标准模板库
- Spring学习笔记:自动创建Proxy
- 文件压缩
- Redis系列-8.键管理
- java基础-个人知识点杂记2.数据库基于日志的恢复
- pandas数据操作
- 技术篇~第一章 数据同步
- C语言之指针专题二:指针做函数参数是指针存在的最大意义
- 线程初步(五)---join,yield
- Java面试题全集(下)
- 写给自己·工作的第5年
- Hive的元数据表结构详解
- 【Spring+MyBatis】-----简介
- 对象监视器,线程关键字synchronized