pandas打开表格修改行索引

import pandas as pd
df = pd.read_csv('E:\\python\\IP\\1.csv')

查看列索引信息

df.index
RangeIndex(start=0, stop=53, step=1)

查看行索引信息

df.columns
Index(['Unnamed: 0', 'Unnamed: 1', 'Unnamed: 2', 'Unnamed: 3', 'Unnamed: 4',
       'Unnamed: 5', 'Unnamed: 6', 'Unnamed: 7', 'Unnamed: 8', 'Unnamed: 9',
       'Unnamed: 10', 'Unnamed: 11', 'Unnamed: 12', 'Unnamed: 13',
       'Unnamed: 14', 'Unnamed: 15', 'Unnamed: 16', 'Unnamed: 17',
       'Unnamed: 18', 'Unnamed: 19', 'Unnamed: 20', 'Unnamed: 21',
       'Unnamed: 22', 'Unnamed: 23', 'Unnamed: 24', 'Unnamed: 25',
       'Unnamed: 26', 'Unnamed: 27', 'Unnamed: 28', 'Unnamed: 29',
       'Unnamed: 30', 'Unnamed: 31', 'Unnamed: 32', 'Unnamed: 33',
       'Unnamed: 34', 'Unnamed: 35', 'Unnamed: 36', 'Unnamed: 37',
       'Unnamed: 38', 'Unnamed: 39', 'Unnamed: 40', 'Unnamed: 41',
       'Unnamed: 42', 'Unnamed: 43', 'Unnamed: 44', 'Unnamed: 45',
       'Unnamed: 46'],
      dtype='object')

转换为numpy数组

arr = df.to_numpy()
arr[0]
array(['科目\\时间', '2019-12-31', '2019-09-30', '2019-06-30', '2019-03-31',
       '2018-12-31', '2018-09-30', '2018-06-30', '2018-03-31',
       '2017-12-31', '2017-09-30', '2017-06-30', '2017-03-31',
       '2016-12-31', '2016-09-30', '2016-06-30', '2016-03-31',
       '2015-12-31', '2015-09-30', '2015-06-30', '2015-03-31',
       '2014-12-31', '2014-09-30', '2014-06-30', '2014-03-31',
       '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31',
       '2012-12-31', '2012-09-30', '2012-06-30', '2012-03-31',
       '2011-12-31', '2011-09-30', '2011-06-30', '2011-03-31',
       '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31',
       '2009-12-31', '2009-09-30', '2009-06-30', '2008-12-31',
       '2007-12-31', '2006-12-31'], dtype=object)

直接设置行名称为首行内容

df.columns=arr[0]
df.columns
Index(['科目\时间', '2019-12-31', '2019-09-30', '2019-06-30', '2019-03-31',
       '2018-12-31', '2018-09-30', '2018-06-30', '2018-03-31', '2017-12-31',
       '2017-09-30', '2017-06-30', '2017-03-31', '2016-12-31', '2016-09-30',
       '2016-06-30', '2016-03-31', '2015-12-31', '2015-09-30', '2015-06-30',
       '2015-03-31', '2014-12-31', '2014-09-30', '2014-06-30', '2014-03-31',
       '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31',
       '2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30',
       '2011-06-30', '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30',
       '2010-03-31', '2009-12-31', '2009-09-30', '2009-06-30', '2008-12-31',
       '2007-12-31', '2006-12-31'],
      dtype='object')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值