Pandas中split()方法如何使用

发布时间:2021-08-11 14:31:03 作者:Leah
来源:亿速云 阅读:277

这期内容当中小编将会给大家带来有关 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 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,并删除索引

结果如下图所示:

PropertyDescription
yearThe year of the datetime
monthThe month of the datetime
dayThe days of the datetime
hourThe hour of the datetime
minuteThe minutes of the datetime
secondThe seconds of the datetime
microsecondThe microseconds of the datetime
nanosecondThe nanoseconds of the datetime
dateReturns datetime.date (does not contain timezone information)
timeReturns datetime.time (does not contain timezone information)
dayofyearThe ordinal day of year
weekofyearThe week ordinal of the year
weekThe week ordinal of the year
dayofweekThe numer of the day of the week with Monday=0, Sunday=6
weekdayThe number of the day of the week with Monday=0, Sunday=6
weekday_nameThe name of the day in a week (ex: Friday)
quarterQuarter of the date: Jan=Mar = 1, Apr-Jun = 2, etc.
days_in_monthThe number of days in the month of the datetime
is_month_startLogical indicating if first day of month (defined by frequency)
is_month_endLogical indicating if last day of month (defined by frequency)
is_quarter_startLogical indicating if first day of quarter (defined by frequency)
is_quarter_endLogical indicating if last day of quarter (defined by frequency)
is_year_startLogical indicating if first day of year (defined by frequency)
is_year_endLogical indicating if last day of year (defined by frequency)
is_leap_yearLogical indicating if the date belongs to a leap year

上述就是小编为大家分享的 Pandas中split()方法如何使用了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. Pandas创建Series的三种方法
  2. 如何设置pandas的参数

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pandas split()

上一篇:SpringMVC方法四种类型返回值的示例分析

下一篇:C语言中的字符串数组怎么表示

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》