网站建设后预期推广方式,17做网店一件代发,公司注册代理费,百度竞价 百度流量 网站权重Series.str可用于以字符串形式访问系列的值并对其应用几种方法。 Pandas Series.str.center()函数用于在系列/索引中的字符串的左侧和右侧填充其他字符。该功能等效于Python的str.center()。用法#xff1a; Series.str.center(width, fillchar’ ‘)参数#xff1a;width:产…Series.str可用于以字符串形式访问系列的值并对其应用几种方法。 Pandas Series.str.center()函数用于在系列/索引中的字符串的左侧和右侧填充其他字符。该功能等效于Python的str.center()。用法 Series.str.center(width, fillchar’ ‘)参数width:产生的字符串的最小宽度其他字符将用fillchar填充fillchar:填充字符默认为空白返回填充范例1采用Series.str.center()函数用“ *”符号填充给定系列对象的基础数据中字符串的左侧和右侧。# importing pandas as pdimport pandas as pd# Creating the Seriessr pd.Series([New_York, Lisbon, Tokyo, Paris, Munich])# Creating the indexidx [City 1, City 2, City 3, City 4, City 5]# set the indexsr.index idx# Print the seriesprint(sr)输出现在我们将使用Series.str.center()函数在字符串的左侧和右侧填充“ *”符号。# fill * in the left and right side of stringresult sr.str.center(width 13, fillchar *)# print the resultprint(result)输出正如我们在输出中看到的Series.str.center()函数已成功在给定系列对象的基础数据中的字符串的左侧和右侧填充了“ *”符号。范例2采用Series.str.center()函数用“ *”符号填充给定系列对象的基础数据中字符串的左侧和右侧。# importing pandas as pdimport pandas as pd# Creating the Seriessr pd.Series([Mike, Alessa, Nick, Kim, Britney])# Creating the indexidx [Name 1, Name 2, Name 3, Name 4, Name 5]# set the indexsr.index idx# Print the seriesprint(sr)输出现在我们将使用Series.str.center()函数在字符串的左侧和右侧填充“ *”符号。# fill * in the left and right side of string# width after filling should be 5result sr.str.center(width 5, fillchar *)# print the resultprint(result)输出正如我们在输出中看到的Series.str.center()函数已成功在给定系列对象的基础数据中的字符串的左侧和右侧填充了“ *”符号。注意如果width的值小于实际字符串的长度则整个字符串将被打印而不会被截断。