[問題] pandas 欄位拷貝跟刪除問題

看板Python作者 (yshihyu)時間7年前 (2017/01/22 22:44), 編輯推噓2(206)
留言8則, 4人參與, 最新討論串1/1
我主要遇到問題是 pandas 表格 columns 欄位拷貝後會連同index數值也拷貝到columns 還有用類似字串切片方式 table index會變得不正確, https://gist.github.com/anonymous/655f0a449970f5f01829d8fd79309a46 上面是我pandas 操作的問題描述, 因為在板上排版格式會跑掉也很亂所以放上面網址 https://gist.github.com/anonymous/581b16a5d07746cc39cd4e46ad0a950f 上面是我的程式碼 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 112.105.250.241 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1485096286.A.97F.html

01/23 01:19, , 1F
1. df2.columns.name = ''
01/23 01:19, 1F

01/23 01:23, , 2F
2. df2.drop(df2.index[0]); df2.index = range(len(df2))
01/23 01:23, 2F

01/23 01:24, , 3F
不過總覺得你的要求有點怪…
01/23 01:24, 3F

01/23 06:40, , 4F
reset_index?
01/23 06:40, 4F

01/23 22:43, , 5F
我剛開始碰 pandas 也和你有相同的疑問
01/23 22:43, 5F

01/23 22:43, , 6F
不過後來都是用 item iter 的方式就無關 index 的事情了
01/23 22:43, 6F

01/24 23:16, , 7F
item iter 的方式是指像下面網址用法嘛?
01/24 23:16, 7F

01/24 23:16, , 8F
01/24 23:16, 8F
文章代碼(AID): #1OXCLUb_ (Python)