Pandas提供了 DataFrame.describe 方法查看数据摘要测试
res.describe() [10 rows x 24 columns] askPrice1 askPrice2 ... bidVolume4 bidVolume5 count 10.0 10.0 ... 10.000000 10.000000 mean 10425.0 10425.5 ... 51242.200000 268655.800000 std 0.0 0.0 ... 2552.554224 2552.554224 min 10425.0 10425.5 ... 49265.000000 265690.000000 25% 10425.0 10425.5 ... 49265.000000 265690.000000 50% 10425.0 10425.5 ... 49265.000000 270633.000000 75% 10425.0 10425.5 ... 54208.000000 270633.000000 max 10425.0 10425.5 ... 54208.000000 270633.000000
DataFrame.isnull() 方法查看数据表中哪些为空值,与它相反的方法是 DataFrame.notnull()code
df.dropna(axis=1, how='all')字符串
通过测试,在 DataFrame.replace() 中使用空字符串,要比默认的空值NaN节省一些空间;但对整个CSV文件来讲,空列只是多存了一个“,”,因此移除的9800万 x 6列也只省下了200M的空间。进一步的数据清洗仍是在移除无用数据和合并上。pandas
使用 DataFrame.dtypes 能够查看每列的数据类型,Pandas默承认以读出int和float64,其它的都处理为object,须要转换格式的通常为日期时间。DataFrame.astype() 方法可对整个DataFrame或某一列进行数据格式转换,支持Python和NumPy的数据类型。io
df['Name'] = df['Name'].astype(np.datetime64)table
对数据聚合,我测试了 DataFrame.groupby 和 DataFrame.pivot_table 以及 pandas.merge ,groupby 9800万行 x 3列的时间为99秒,链接表为26秒,生成透视表的速度更快,仅需5秒。ast
df.groupby(['NO','TIME','SVID']).count() # 分组
fullData = pd.merge(df, trancodeData)[['NO','SVID','TIME','CLASS','TYPE']] # 链接
actions = fullData.pivot_table('SVID', columns='TYPE', aggfunc='count') # 透视表object