1. 程式人生 > >python-dataframe

python-dataframe

frame=DataFrame(np.arange(9).reshape((3,3)),index=['a','c','d'],
                columns=['Ohio','Texas','California'])
#print(frame)
'''   Ohio  Texas  California
a     0      1           2
c     3      4           5
d     6      7           8'''
frame2=frame.reindex(['a','b','c','d'])
#print(frame2)
'''  Ohio  Texas  California
a   0.0    1.0         2.0
b   NaN    NaN         NaN
c   3.0    4.0         5.0
d   6.0    7.0         8.0'''
states=['Texas','Utah','California']
frame22=frame.reindex(columns=states)
# print(frame22.reindex(index=['a','b','c','d'],method='ffill',columns=states))
#print(frame22.ix[['a','b','c','d'],states])
obj=Series(np.arange(5),index=['a','b','c','d','e'])
new_obj=obj.drop('c')
'''print(new_obj)
obj1=obj.drop(['c','d'])
print(obj1)
data=DataFrame(np.arange(16).reshape((4,4)),index=['Ohio','Colorado','Utah','New York'],
               columns=['one','two','three','four'])
#print(data.drop(['Colorado','Ohio']))
print(data.drop('two',axis=1))'''
'''obj=Series(np.arange(4),index=['a','b','c','d'])
print(obj['b'])
print(obj[1])
print(obj[2:4])
print(obj['b':'c'])'''
data=DataFrame(np.arange(16).reshape((4,4)),index=['Ohio','Colorado','Utah','New York'],
               columns=['one','two','three','four'])
print(data)
'''          one  two  three  four
Ohio        0    1      2     3
Colorado    4    5      6     7
Utah        8    9     10    11
New York   12   13     14    15'''
'''print(data['two'])
print(data<5)
data[data<5]=5
print(data)'''
'''print(data.ix['Colorado',['two','three']])
print(data.ix[['Colorado','Utah'],[3,0,1]])'''
#print(data.ix[2])
'''one       8
two       9
three    10
four     11
Name: Utah, dtype: int32'''
def1=DataFrame(np.arange(9).reshape((3,3)),columns=list('bdc'),index=['Ohio','Texas','Colorado'])
def2=DataFrame(np.arange(12).reshape((4,3)),columns=list('bde'),index=['Utah','Ohio','Texas','Oregon'])
#print(def1)
'''          b  d  c
Ohio      0  1  2
Texas     3  4  5
Colorado  6  7  8'''
#print(def2)
'''        b   d   e
Utah    0   1   2
Ohio    3   4   5
Texas   6   7   8
Oregon  9  10  11'''