這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān) Pandas中split()方法如何使用,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)于2013年成立,先為開(kāi)封等服務(wù)建站,開(kāi)封等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為開(kāi)封企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
split()正序分割列;rsplit()逆序分割列
Series.str.split(pat=None, n=-1, expand=False)
參數(shù):
pat : 字符串,默認(rèn)使用空白分割.
n : 整型,默認(rèn)為-1,既使用所有的分割點(diǎn)分割
expand : 布爾值,默認(rèn)為False.如果為真返回?cái)?shù)據(jù)框(DataFrame)或復(fù)雜索引(MultiIndex);如果為True,返回序列(Series)或者索引(Index).
return_type : 棄用,使用spand參數(shù)代替
返回值:
split : 參考expand參數(shù)
例子:
將一下列表按第一個(gè)空格分割成兩個(gè)列表,列表的名稱分別是“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#按第一個(gè)空格分割df.drop("Property Description",axis=1,inplace=True)#刪除原有的列df.to_csv("C:/Users/Administrator/Desktop/New Microsoft Excel 工作表.csv",index=False)#保存為csv,并刪除索引
結(jié)果如下圖所示:
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()方法如何使用了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。