简体   繁体   English

str(Series).split() 和 Series.str.split() 有什么区别?

[英]What is the difference between str(Series).split() and Series.str.split()?

I wanted to know conceptually why there is difference in output using str(Series).split() and Series.str.split() , when using it on the series object .我想从概念上知道为什么在使用str(Series).split() 和 Series.str.split()时,在series object上使用它时输出会有所不同。 I was looking to split the date based on the punctuation: the str(Series).split() didn't give me the desired output while the other method, using Series.str.split() but I heard that using the [dot] accessor is frowned upon.我想根据标点符号分割日期: str(Series).split() 没有给我想要的输出,而另一种方法,使用 Series.str.split() 但我听说使用 [dot ] 存取器不赞成。 I've searched the net but I did not get any satisfactory answers.我搜索了网络,但没有得到任何满意的答案。 Can anyone help me out and shed some light?任何人都可以帮助我并阐明一些观点吗? I was using the following series object.我正在使用以下系列对象。

df5 = pd.Series(["04/20/2009", "04/20/09", "4/20/09", "4/3/09", "Mar-20-2009", "Mar 20, 2009", "March 20, 2009", "Mar. 20, 2009", "Mar 20 2009", "20 Mar 2009","20 March 2009", "20 Mar. 2009", "20 March, 2009", "Mar 20th, 2009", "Mar 21st, 2009", "Mar 22nd, 2009", "Feb 2009", "Sep 2009", "Oct 2010", "6/2008","12/2009", "2009", "2010"])

str(series).split() functions similar to concatenating the series object into a string and then splits it on a specified delimiter (in this case, since it is empty, it'll use space as a delimiter). str(series).split()函数类似于将系列对象连接成一个字符串,然后在指定的分隔符上拆分它(在这种情况下,由于它是空的,它将使用空格作为分隔符)。

On the other hand, series.str.split() will function similar to mapping each string of the series object to the split function which would give you a series object with a list of strings for each string in the original series object.另一方面, series.str.split()功能类似于将系列对象的每个字符串映射到 split 函数,该函数将为您提供一个系列对象,其中包含原始系列对象中每个字符串的字符串列表。

Here is the official documentation for series.str.split() for more info. 这是series.str.split() 的官方文档以获取更多信息。

Also, the dot operator is generally frowned upon when it's used to access a dataframe column, as it won't work if the column has a whitespace in the name.此外,当使用点运算符访问数据框列时,通常不赞成使用它,因为如果该列的名称中有空格,它就不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM