pandas.DataFrame.add_suffix#
- DataFrame.add_suffix(suffix)[源代码]#
使用字符串为标签添加后缀 suffix 。
对于系列,行标签带有后缀。对于DataFrame,列标签带有后缀。
- 参数
- suffix应力
要添加到每个标签之后的字符串。
- 退货
- 系列或DataFrame
具有更新标签的新系列或DataFrame。
参见
Series.add_prefix
使用字符串作为行标签的前缀 prefix 。
DataFrame.add_prefix
使用字符串作为列标签的前缀 prefix 。
示例
>>> s = pd.Series([1, 2, 3, 4]) >>> s 0 1 1 2 2 3 3 4 dtype: int64
>>> s.add_suffix('_item') 0_item 1 1_item 2 2_item 3 3_item 4 dtype: int64
>>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]}) >>> df A B 0 1 3 1 2 4 2 3 5 3 4 6
>>> df.add_suffix('_col') A_col B_col 0 1 3 1 2 4 2 3 5 3 4 6