Pandas 文本数据方法 pad( ) center( ) ljust() rjust() zfill()
2017-03-22 19:09
393 查看
Series.str.pad(width, side=’left’, fillchar=’ ‘)设置字符串的宽度
参数:
width : 整型,字符串最小的宽度
side : {‘left’, ‘right’, ‘both’}填充的方向
fillchar : 字符串,空白的地方填充的东西
返回值:
序列Series/索引Index
Series.str.center(width, fillchar=’ ‘)设置字符的宽度,从两边填充,等同于pad(side=”both”)
参数:
width : 整型,最小宽度
fillchar : 字符串,填充内容
返回值:
序列Series/索引Index
Series.str.ljust(width, fillchar=’ ‘)设置字符的宽度,从两边填充,等同于pad(side=”right”)
参数:
width : 整型,最小宽度
fillchar : 字符串,填充内容
返回值:
序列Series/索引Index
Series.str.rjust(width, fillchar=’ ‘)等同于pad(side=”left”)字符串右移
Series.str.zfill(width)等同于pad(with,side=”left”,fillchar=”0”)0填充
参数:
width : 整型,字符串最小的宽度
side : {‘left’, ‘right’, ‘both’}填充的方向
fillchar : 字符串,空白的地方填充的东西
返回值:
序列Series/索引Index
import pandas as pd s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA', 'dog', 'cat']) print(s.str.pad(5,side="left",fillchar="a")) 0 aaaaA 1 aaaaB 2 aaaaC 3 aAaba 4 aBaca 5 aCABA 6 aadog 7 aacat dtype: object
Series.str.center(width, fillchar=’ ‘)设置字符的宽度,从两边填充,等同于pad(side=”both”)
参数:
width : 整型,最小宽度
fillchar : 字符串,填充内容
返回值:
序列Series/索引Index
import pandas as pd s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA', 'dog', 'cat']) print(s.str.center(5,fillchar="a")) 0 aaAaa 1 aaBaa 2 aaCaa 3 aAaba 4 aBaca 5 aCABA 6 adoga 7 acata dtype: object
Series.str.ljust(width, fillchar=’ ‘)设置字符的宽度,从两边填充,等同于pad(side=”right”)
参数:
width : 整型,最小宽度
fillchar : 字符串,填充内容
返回值:
序列Series/索引Index
import pandas as pd s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA', 'dog', 'cat']) print(s.str.ljust(5,fillchar="a")) 0 Aaaaa 1 Baaaa 2 Caaaa 3 Aabaa 4 Bacaa 5 CABAa 6 dogaa 7 cataa dtype: object
Series.str.rjust(width, fillchar=’ ‘)等同于pad(side=”left”)字符串右移
Series.str.zfill(width)等同于pad(with,side=”left”,fillchar=”0”)0填充
相关文章推荐
- Pandas 文本数据方法 pad( ) center( ) ljust() rjust() zfill()
- Pandas 文本数据方法 slice( )
- Pandas 文本数据方法 get_dummies()
- Pandas 文本数据方法 capitalize( ) lower( ) upper( )
- Pandas 文本数据方法 startswith( ) endwith( )
- Pandas 文本数据方法 find( ) rfind( ) index( ) rindex( )
- python ljust,rjust,center,zfill对齐使用方法
- python中字符串的ljust、rjust、center方法讲解
- Pandas 文本数据方法 is*()
- Pandas 文本数据方法 strip( ) lstrip( ) rstrip( )
- Pandas 文本数据方法 slice( )
- Pandas 文本数据方法 get( )
- Pandas 文本数据方法 startswith( ) endwith( )
- Pandas 文本数据方法 replace( )
- Pandas 文本数据方法 count( )
- Pandas 文本数据方法 join( )
- python中字符串的ljust、rjust、center方法讲解
- Pandas 文本数据方法 findall( )
- Pandas 文本数据方法 contains()
- Pandas 文本数据方法 extract( ) extractall( )