Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the split () method in Pandas

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to use the split () method in Pandas. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Split () positive order partition column; rsplit () reverse order partition column

Series.str.split (pat=None, nasty Murray 1, expand=False)

Parameters:

Pat: string, which is separated by white space by default.

N: integer, default is-1, split using all split points

Expand: Boolean value, default is False. Returns a data box (DataFrame) or complex index (MultiIndex) if true, or a sequence (Series) or index (Index) if True.

Return_type: deprecate, use the spand parameter instead

Return value:

Split: reference expand parameter

Example:

Divide the following list into two lists by the first space, with the names "Property" and "Description", respectively.

Property Descriptionyear The year of the datetimemonth The month of the datetimeday The days of the datetimehour The hour of the datetimeminute The minutes of the datetimesecond The seconds of the datetimemicrosecond The microseconds of the datetimenanosecond The nanoseconds of the datetimedate Returns datetime.date (does not contain timezone information) time Returns datetime.time (does not contain timezone information) dayofyear The ordinal dayof yearweekofyear The week ordinal of the yearweek The week ordinal of the yeardayofweek The numer of the dayof the week with Monday=0, Sunday=6weekday The number of the dayof the week with Monday=0, Sunday=6weekday_name The name of the day ina 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 datetimeis_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 yearimport pandas as pddf=pd.read_excel ("C:/Users/Administrator/Desktop/New Microsoft Excel worksheet .xlsx") # read worksheet df ["Property"] Df ["Description"] = df ["Property Description"] .str.split (", nail1) .str # split by the first space df.drop (" Property Description ", axis=1,inplace=True) # delete the original column df.to_csv (" C:/Users/Administrator/Desktop/New Microsoft Excel worksheet .csv ", index=False) # Save as csv And delete the index

The result is shown in the following figure:

PropertyDescriptionyearThe year of the datetimemonthThe month of the datetimedayThe days of the datetimehourThe hour of the datetimeminuteThe minutes of the datetimesecondThe seconds of the datetimemicrosecondThe microseconds of the datetimenanosecondThe nanoseconds of the datetimedateReturns datetime.date (does not contain timezone information) timeReturns datetime.time (does not contain timezone information) dayofyearThe ordinal dayof yearweekofyearThe week ordinal of the yearweekThe week ordinal of the yeardayofweekThe numer of the dayof the week with Monday=0, Sunday=6weekdayThe number of the dayof the week with Monday=0, Sunday=6weekday_nameThe name of the day ina 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 datetimeis_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 above is how the split () method is used in Pandas that the editor shares with you. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report