pandas.Series.to_string#

Series.to_string(buf=None, na_rep='NaN', float_format=None, header=True, index=True, length=False, dtype=False, name=False, max_rows=None, min_rows=None)[源代码]#

渲染 Series 的字符串表示。

Parameters:
bufStringIO 类文件流,可选

要写入的缓冲区。

na_repbool, default False

NaN 的字符串表示形式,默认为 ‘NaN’。

float_format单参数函数,可选

如果列的元素是浮点数,则应用于列元素的格式化函数,默认为 None。

headerbool, default True

添加 Series 的标题(索引名称)。

indexbool, optional

添加索引(行)标签,默认为 True。

lengthbool,默认 False

添加 Series 的长度。

dtypebool,默认 False

添加 Series 的 dtype。

namebool,默认 False

添加 Series 的名称(如果存在)。

max_rowsint, optional

在截断之前要显示的最多行数。如果为 None,则显示所有行。

min_rowsint, optional

在截断的 repr 中显示的行数(当行数超过 max_rows 时)。

Returns:
str 或 None

Series 的字符串表示形式(如果 buf=None),否则为 None。

Examples

>>> ser = pd.Series([1, 2, 3]).to_string()
>>> ser
'0    1\n1    2\n2    3'