#1将列标签c1、c2、c3、c4修改为column1、column2、column3、column4 #2将第四行、第二列的数据13改为14 #3使用loc函数 为对象df1添加一行数据标签为i5 值为17 18 19 20 #4使用drop函数 将df1对象的行标签为i5的行删除并输出df1完整示例
import pandas as pd
创建示例数据
data = {'c1': [1, 2, 3, 4], 'c2': [5, 6, 7, 8], 'c3': [9, 10, 11, 12], 'c4': [13, 14, 15, 16]} df1 = pd.DataFrame(data, index=['i1', 'i2', 'i3', 'i4'])
1. 将列标签c1、c2、c3、c4修改为column1、column2、column3、column4
df1 = df1.rename(columns={'c1': 'column1', 'c2': 'column2', 'c3': 'column3', 'c4': 'column4'})
2. 将第四行、第二列的数据13改为14
df1.at['i4', 'column2'] = 14
3. 使用loc函数 为对象df1添加一行数据标签为i5 值为17 18 19 20
df1.loc['i5'] = [17, 18, 19, 20]
4. 使用drop函数 将df1对象的行标签为i5的行删除,并输出df1完整示例
df1 = df1.drop('i5') print(df1)
原文地址: https://www.cveoy.top/t/topic/brvk 著作权归作者所有。请勿转载和采集!