在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使用pip安装报错:is not a supported wheel on this platform的解决方法

Python使用pip安装报错:is not a supported wheel on this platform的解决方法

本文讲述了Python使用pip安装报错:is not a supported wheel on this platform的解决方法。分享给大家供大家参考,具体如下: 可能的原因1:安...

python中的TCP(传输控制协议)用法实例分析

本文实例讲述了python中的TCP(传输控制协议)用法。分享给大家供大家参考,具体如下: 1.TCP与UDP的不同: windows网络调试助手下载:https://pan.baidu...

利用Python演示数型数据结构的教程

使用 Python 内建的defaultdict 方法可以轻松定义一个树的数据结构。 简单的说树也可以是一个字典数据结构   def tree(): return def...

python用10行代码实现对黄色图片的检测功能

本文实例讲述了python用10行代码实现对黄色图片的检测功能。分享给大家供大家参考。具体如下: 原理:将图片转换为YCbCr模式,在图片中寻找图片色值像素,如果在皮肤色值内的像素面积超...

详解Django-channels 实现WebSocket实例

引入 先安装三个模块 pip install channels pip install channels_redis pip install pywin32 创建一个Dja...