码迷,mamicode.com
首页 > 其他好文 > 详细

pandas学习

时间:2017-05-11 18:29:02      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:art   imp   ==   read   span   csv   label   numpy   and   

1.读入数据

#-*- coding:utf-8 -*-
import numpy as np
import pandas as pd
df_data = pd.read_csv(filename,sep=\t,header=False,names=[distance,pid,time,fee])
#http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

2.ix

df_data.ix[df_data[carpool]==1,discount] = 1-df_data[discount_fee]/df_data[total_fee]

df_sofa[‘start_gird‘] = df_sofa[[‘start_lat‘,‘start_lng‘]].apply(lambda x:get_HexCellKey(x[0],x[1]),axis=1)

3.DataFrame

time_split = pd.DataFrame((x.split( ) for x in data.bubble_time),index=data.index,columns=[day,h])

4.cut

bins_p = [0, 30, 40, 60, 80, 400]
group_names_p = [10, 30, 40, 60, 80]
data[price] = pd.cut(data[total_fee], bins_p, labels=group_names_p)

5.sort_values

data=data.sort_values(by=[pid,time],ascending=True)

pandas学习

标签:art   imp   ==   read   span   csv   label   numpy   and   

原文地址:http://www.cnblogs.com/rongxxx/p/6842035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!