在Python中pandas.DataFrame重置索引名称的实例

yipeiwu_com6年前Python基础

例子:

创建DataFrame

### 导入模块
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
 
test = pd.DataFrame({'a':[11,22,33],'b':[44,55,66]})
"""
  a  b
0 11 44
1 22 55
2 33 66
"""

更改列名方法一:rename

test.rename(columns={'a':'c'},inplace=True)
"""
  c  b
0 11 44
1 22 55
2 33 66
""""

更改列明方法二:直接赋值

test.columns = ['c','b']

以上这篇在Python中pandas.DataFrame重置索引名称的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

原生python实现knn分类算法

原生python实现knn分类算法

一、题目要求 用原生Python实现knn分类算法。 二、题目分析 数据来源:鸢尾花数据集(见附录Iris.txt) 数据集包含150个数据集,分为3类,分别是:Iris Setosa(...

简单了解python高阶函数map/reduce

简单了解python高阶函数map/reduce

高阶函数map/reduce Python内建了map()和reduce()函数。 我们先看map。map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数...

python在html中插入简单的代码并加上时间戳的方法

python在html中插入简单的代码并加上时间戳的方法

建议用pycharm,使用比较方便,并且可以直接编辑html文件 import time locatime = time.strftime("%Y-%m-%d" ) report =...

python pands实现execl转csv 并修改csv指定列的方法

如下所示: # -*- coding: utf-8 -*- import os import pandas as pd import numpy as np #from os im...

python list多级排序知识点总结

在python3的sorted中去掉了cmp参数,转而推荐“key+lambda”的方式来排序。 如果需要对python的list进行多级排序。有如下的数据: list_num =...