Python Pandas dataframe.add_suffix()

Python Pandas dataframe.add_suffix()

Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Dataframe.add_suffix()函数既可用于系列,也可用于数据框。 add_suffix()函数 将后缀字符串与面板项目名称相衔接

  • 对于系列,行标签是有后缀的。
  • 对于DataFrame,列标签是有后缀的。

语法: DataFrame.add_suffix(suffix)

参数:
suffix : string

返回值: with_suffix: type of caller

例子#1:数据框架中每一列的后缀_col。

# importing pandas as pd
import pandas as pd
  
# Making data frame from the csv file
df = pd.read_csv("nba.csv")
  
# Printing the first 10 rows of
# the data frame for visualization
df[:10]
Python

Python Pandas dataframe.add_suffix()

# Using add_suffix() function to 
# add '_col' in each column label
df = df.add_suffix('_col')
  
# Print the dataframe
df 
Python

输出:
Python Pandas dataframe.add_suffix()

例子#2:在pandas中使用add_suffix()与系列。

add_suffix()在系列的情况下改变了行索引标签。

# importing pandas as pd
import pandas as pd
  
# Creating a Series 
df = pd.Series([1, 2, 3, 4, 5, 10, 11, 21, 4])
  
# This will suffix '_Row' in
# each row of the series
df = df.add_suffix('_Row')
  
# Print the Series
df
Python

输出:
Python Pandas dataframe.add_suffix()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册