pandas学习(三)

1.从dataframe中删除一列

del DF['column-name'],

DF.drop('column_name', axis=1, inplace=True)
DF = DF.drop('column_name', 1)

2.从dataframe中删除多列

删除多列df.drop([Column Name or list],inplace=True,axis=1)
DF.drop([DF.columns[[0, 1, 3]]], axis=1) 

3.从dataframe中在指定位置插入一列

 

using idx = 0 will insert at the beginning

df.insert(idx, col_name, value)

4.调换dataframe中列

5.找出指定行的重复数量

df.index[(df == [3, 1, 1, 0]).all(axis=1)]
Int64Index([2, 3], dtype=int64)
还有一种情况:

male_trips是一个大dataframe,stations是一个小dataframe.对每个station id ,我想知道 male trips中有多少行对应.命令式:

df = male_trips.groupby('start_station_id').size()

6.对dataframe,根据列名称,或者列序号进行分组,并查看每个分组的行数

df_1.groupby([0,1,2,3,4]).size()

结果:

0  1  2  3  4
0  0  0  0  0    9896
            1     101
         1  0      43
            1       1
      1  1  0      99
            1       2
   1  0  0  0       7
      1  1  1       2
1  1  0  0  0       9
            1      13
         1  0       6
            1      42
      1  1  0     202
            1     827


7.dataframe中,将column名称以numpy.array形式生成

feature_names = df.columns.values[:19]

8.将两个array形成一个list

c = zip(clf_et.feature_importances_,feature_names)

9.两个值对比,python显示结果为布尔值

in:c[7][0]>c[0][0]

out:False




你可能感兴趣的:(pandas学习(三))