使用Python的Dataframe取两列时间值相差一年的所有行方法
在使用Python处理数据时,经常需要对数据筛选。
这是在对时间筛选时,判断两列时间是否相差一年,如果是,则返回符合条件的所有列。
data原始数据:
data[map(lambdax:datetime.date(x.year-1,x.month,x.day),data['report_date'])==data['date_1y_ago']] company_idsignal_code_xsignal_value_xreport_datesignal_code_ysignal_value_yreport_date_lastdate_1y_ago 02154888r_10020300000.626602015-09-30r_10020300000.641452015-12-312014-12-31 12154888r_10020300000.641452015-12-31r_10020300000.641452015-12-312014-12-31 22154888r_10020300000.605442015-03-31r_10020300000.641452015-12-312014-12-31 32154888r_10020300000.549112014-12-31r_10020300000.641452015-12-312014-12-31 42154888r_10020300000.613792015-06-30r_10020300000.641452015-12-312014-12-31 51702887r_10020300000.621732014-03-31r_10020300000.511032015-03-312014-03-31 61702887r_10020300000.551752014-12-31r_10020300000.511032015-03-312014-03-31 71702887r_10020300000.511032015-03-31r_10020300000.511032015-03-312014-03-31 81702887r_10020300000.586962014-06-30r_10020300000.511032015-03-312014-03-31 913484491r_10020300000.176582014-12-31r_10020300000.410822015-12-312014-12-31 1013484491r_10020300000.410822015-12-31r_10020300000.410822015-12-312014-12-31 1113484491r_10020300000.392202015-09-30r_10020300000.410822015-12-312014-12-31
筛选后的数据:
company_idsignal_code_xsignal_value_xreport_datesignal_code_ysignal_value_yreport_date_lastdate_1y_ago 12154888r_10020300000.641452015-12-31r_10020300000.641452015-12-312014-12-31 71702887r_10020300000.511032015-03-31r_10020300000.511032015-03-312014-03-31 1013484491r_10020300000.410822015-12-31r_10020300000.410822015-12-312014-12-31
以上这篇使用Python的Dataframe取两列时间值相差一年的所有行方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。