Pandas中split()方法如何使用
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这期内容当中小编将会给大家带来有关 Pandas中split()方法如何使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。split()正序分割列;rsplit()
千家信息网最后更新 2026年11月01日Pandas中split()方法如何使用
这期内容当中小编将会给大家带来有关 Pandas中split()方法如何使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
split()正序分割列;rsplit()逆序分割列
Series.str.split(pat=None, n=-1, expand=False)
参数:
pat : 字符串,默认使用空白分割.
n : 整型,默认为-1,既使用所有的分割点分割
expand : 布尔值,默认为False.如果为真返回数据框(DataFrame)或复杂索引(MultiIndex);如果为True,返回序列(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 pddf=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()方法如何使用了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。
参数
索引
工作
方法
内容
空格
分析
复杂
专业
两个
中小
例子
内容丰富
名称
字符
字符串
就是
布尔
序列
数据
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技工作委员会毛军
美国互联网科技巨头监管
重庆互联网络科技
科技制造互联网公司
安徽鑫晟辉互联网科技
深圳期待互联网科技
成都互联网科技公司100强
北京华百购互联网科技有限公司
移动互联网科技股
受益于互联网科技的高速发展
浙江互联网科技研学营
苏州五指互联网络科技有限
花神(南京)互联网科技有限公司
中国互联网十大科技股排名
乌苏新华互联网科技做什么的
九思连强互联网电子科技有限公司
张家口科技产业互联网平台
米泉互联网科技专业怎么样
广州三三互联网科技有限公司
唐山双旺合互联网科技产业园
上海挚品互联网科技有限公司
互联网加科技
互联网科技产业
西安互联网科技
互联网科技缩写
居家互联网科技有限公司
互联网科技生活的内容
燊美集互联网科技有限公司
互联网方面的科技前沿
青岛易易互联网科技