Pandas 文本数据方法 split()rsplit()
split()正序分割列;rsplit()逆序分割列
Series.str.split(pat=None, n=-1, expand=False)
参数:
pat : 字符串,默认使用空白分割.
n : 整型,默认为-1,既使用所有的分割点分割
expand : 布尔值,默认为False.如果为真返回数据框(DataFrame)或复杂索引(MultiIndex);如果为假,返回序列(Series)或者索引(Index).
return_type : 弃用,使用spand参数代替
返回值:
split : 参考expand参数
例子:
将一下列表按第一个空格分割成两个列表,列表的名称分别是“Property”和“Description”
Property Description |
year The year of the datetime |
month The month of the datetime |
day The days of the datetime |
hour The hour of the datetime |
minute The minutes of the datetime |
second The seconds of the datetime |
microsecond The microseconds of the datetime |
nanosecond The nanoseconds of the datetime |
date Returns datetime.date (does not contain timezone information) |
time Returns datetime.time (does not contain timezone information) |
dayofyear The ordinal day of year |
weekofyear The week ordinal of the year |
week The week ordinal of the year |
dayofweek The numer of the day of the week with Monday=0, Sunday=6 |
weekday The number of the day of the week with Monday=0, Sunday=6 |
weekday_name The name of the day in a week (ex: Friday) |
quarter Quarter of the date: Jan=Mar = 1, Apr-Jun = 2, etc. |
days_in_month The number of days in the month of the datetime |
is_month_start Logical indicating if first day of month (defined by frequency) |
is_month_end Logical indicating if last day of month (defined by frequency) |
is_quarter_start Logical indicating if first day of quarter (defined by frequency) |
is_quarter_end Logical indicating if last day of quarter (defined by frequency) |
is_year_start Logical indicating if first day of year (defined by frequency) |
is_year_end Logical indicating if last day of year (defined by frequency) |
is_leap_year Logical indicating if the date belongs to a leap year |
import pandas as pd
df=pd.read_excel("C:/Users/Administrator/Desktop/New Microsoft Excel 工作表.xlsx")#读取工作表
df["Property"],df["Description"]=df["Property Description"].str.split(" ",n=1).str#按第一个空格分割
df.drop("Property Description",axis=1,inplace=True)#删除原有的列
df.to_csv("C:/Users/Administrator/Desktop/New Microsoft Excel 工作表.csv",index=False)#保存为csv,并删除索引
结果如下图所示:
Property | Description |
year | The year of the datetime |
month | The month of the datetime |
day | The days of the datetime |
hour | The hour of the datetime |
minute | The minutes of the datetime |
second | The seconds of the datetime |
microsecond | The microseconds of the datetime |
nanosecond | The nanoseconds of the datetime |
date | Returns datetime.date (does not contain timezone information) |
time | Returns datetime.time (does not contain timezone information) |
dayofyear | The ordinal day of year |
weekofyear | The week ordinal of the year |
week | The week ordinal of the year |
dayofweek | The numer of the day of the week with Monday=0, Sunday=6 |
weekday | The number of the day of the week with Monday=0, Sunday=6 |
weekday_name | The name of the day in a week (ex: Friday) |
quarter | Quarter of the date: Jan=Mar = 1, Apr-Jun = 2, etc. |
days_in_month | The number of days in the month of the datetime |
is_month_start | Logical indicating if first day of month (defined by frequency) |
is_month_end | Logical indicating if last day of month (defined by frequency) |
is_quarter_start | Logical indicating if first day of quarter (defined by frequency) |
is_quarter_end | Logical indicating if last day of quarter (defined by frequency) |
is_year_start | Logical indicating if first day of year (defined by frequency) |
is_year_end | Logical indicating if last day of year (defined by frequency) |
is_leap_year | Logical indicating if the date belongs to a leap year |
Pandas 文本数据方法 split()rsplit()相关推荐
- Pandas 文本数据方法 partition( )
Series.str.partition(pat=' ', expand=True)从左边分割字符串,相比split保留分隔符 Series.str.rpartition(pat=' ', expan ...
- Pandas 文本数据方法 capitalize( ) lower( ) upper( )
Series.str.capitalize()首字母大写 import pandas as pd s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA ...
- Pandas 文本数据方法 find( ) rfind( ) index( ) rindex( )
Series.str.find(sub, start=0, end=None)????????,???? Series.str.rfind(sub, start=0, end=None)??????? ...
- Pandas 文本数据方法 extract( ) extractall( )
Series.str.extract(pat, flags=0, expand=None) 参数: pat : 字符串或正则表达式 flags : 整型, expand : 布尔型,是否返回数据框 R ...
- Pandas 文本数据方法 findall( )
Series.str.findall(pat, flags=0, **kwargs)返回要查询的内容 参数: pat : 字符串或正则 flags : 整型, 返回: 序列Series/索引Index ...
- Pandas 文本数据方法 count( )
Series.str.count(pat, flags=0, **kwargs)查看字符在各个元素中出现的次数 参数: pat : 字符串或正则 flags : 整型 Returns: 序列Serie ...
- Pandas 文本数据方法 wrap( )
Series.str.wrap(width, **kwargs)包裹字符串 参数: width : 整型,最小字符串长度 expand_tabs : 布尔型, 默认为True,tab也会被包裹 rep ...
- Pandas 文本数据方法 get_dummies()
Series.str.get_dummies(sep='|')分割字符串并返回各个字符的复杂矩阵 参数: sep : 字符串, 默认为"|" 返回值: 数据框(DataFrame) ...
- Pandas 文本数据方法 join( )
Series.str.join(sep)在字符之间插入分隔符 参数: sep : 字符串,要插入的分隔符 返回值: 序列(Series)/索引(Index) import pandas as pd s ...
最新文章
- 软件公司因女员工怀二胎拒绝与其续约
- 数据库实时转移之Confluent介绍(一)
- Ardino基础教程 11_PWM调控灯光亮度
- 利用规划图提高经典人工智能规划复杂度
- parted命令 Linux 分区超过2TB硬盘
- spring security4 问题
- select2多选框无法手动排序问题[转载]
- wojilu系统的ORM代码解析-[源代码结构分析,用特性和反射来感知属性-特性介绍篇]...
- 人工神经网络MATLAB例子,matlab人工神经网络模型
- 云原生时代——投资人视角下的云原生趋势思考
- sqlrelay mysql_SQL Relay使用
- 下载Idea以及破解使用至2100年
- 技术分享 | Frida 实现 Hook 功能的强大能力
- 电影《暮光之城》不得不爱
- cPanel主机自定义php.ini文件
- 《网络是怎样连接的》-----户根勤,读书笔记
- 中亦安图递交注册:拟募资6亿 年营收近12亿
- 怎么将webm文件转换成MP4格式在手机上播放
- 牛客2019跨年AK场 E	【大】约数 (两个数的全部公约数)
- MongoDB 学习笔记
热门文章
- 微课|中学生可以这样学Python(8.3节):递推算法例题讲解
- Python裸奔也疯狂:批量爬取中国工程院院士信息
- dos进入mysql不记得密码_windos mysql 忘记密码,无密码登录,重新登录
- 网络 一篇博文搞懂五种常见的IO模型
- 中职计算机英语教师教学总结,中职计算机教师教学工作总结 (3000字).doc
- KMP算法经典题目--实现 strStr()
- 力扣513. 找树左下角的值(JavaScript)
- C++新特性探究(6.1):auto和decltype的类型推断差异所在
- c语言实现可变单链表,c语言实现单链表
- 国防科技大学计算机学院教授陈书民,国防科技大学刘新旺教授做客信息学院