pandas之重排分級資料到整數索引
阿新 • • 發佈:2019-01-07
# coding: utf-8
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['F:\\c++\\callGBDT', 'F:/c++/callGBDT'])
get_ipython().magic(u'save d:/log.txt')
get_ipython().magic(u'save d:/log.txt%')
get_ipython().magic(u'save d:\\\\log.txt%')
get_ipython().magic(u'save -r d:\\\\log.txt%' )
import
(/)
get_ipython().magic(u'save :d:/log.txt')
get_ipython().magic(u'save d:/log.txt')
get_ipython().magic(u'save -r d:/log.txt')
get_ipython().magic(u'save')
get_ipython().magic(u'save log.txt')
hh
from pandas import *
get_ipython().magic(u'save log.txt')
get_ipython().magic(u'cls ')
get_ipython().magic(u'save d:/log.txt' )
get_ipython().magic(u'save d:/log.txt 1:')
get_ipython().magic(u'save d:/log.txt 1:1000')
get_ipython().magic(u'cls')
get_ipython().magic(u'cls ')
frame=DataFrame(np.arange(12).reshape((4,3)),index=['a','a','b','b'],[1,2,1,2],columns=[['Ohio','Ohio','Colorado'],['Green','Red','Green']])
frame=DataFrame(np.arange(12 ).reshape((4,3)),index=['a','a','b','b'],[1,2,1,2],columns=[['Ohio','Ohio','Colorado'],['Green','Red','Green']])
import numpy as np
frame=DataFrame(np.arange(12).reshape((4,3)),index=['a','a','b','b'],[1,2,1,2],columns=[['Ohio','Ohio','Colorado'],['Green','Red','Green']])
from pandas import *
import pandas as pd;
frame=DataFrame(np.arange(12).reshape((4,3)),index=['a','a','b','b'],[1,2,1,2],columns=[['Ohio','Ohio','Colorado'],['Green','Red','Green']])
frame=DataFrame(np.arange(12).reshape((4,3)),index=[['a','a','b','b'],[1,2,1,2]],columns=[['Ohio','Ohio','Colorado'],['Green','Red','Green']])
frame
frame.index.names=['key1','key2']
frame.columns.names=['state','color']
frame
frame.swaplevel('key1','key2')
frame.index.names
frame
frame.sortlevel(1)
frame.swaplevel(0,1).sortlevel(1)
frame.swaplevel(0,1).sortlevel(0)
frame
frame.sum(level='key2')
frame
frame.sum(level='color',axis=1)
frame =DataFrame({'a':range(7),'b':range(7,0,-1),'c':['one','one','one','one','two','two','two','two'],'d':[0,1,2,0,1,2,3]})
frame =DataFrame({'a':range(7),'b':range(7,0,-1),'c':['one','one','one','two','two','two','two'],'d':[0,1,2,0,1,2,3]})
frame
frame2=frame.set_index(['c','d'])
frame2
frame2=frame.set_index(['c','d'],drop = False)
frame2
frame2.reset_index()
ser=Series(np.arange(3.))
ser[-1]
ser
ser2=Series(np.arange(3.),index=['a','b','c'])
ser2
ser[-1]
ser2[-1]
ser2
ser
ser.ix[:1]
ser3=Series(range(3),index=[-5,1,3])
ser3
ser3.iget_value(2)
frame=DataFrame(np.arange(6).reshape(3,2),index=[2,0,1])
frame
frame.irow(0)
get_ipython().magic(u'save d:/log 1:1000')