在使用Python处理数据时,经常需要对数据筛选。
这是在对时间筛选时,判断两列时间是否相差一年,如果是,则返回符合条件的所有列。
data原始数据:
data[map(lambda x:datetime.date(x.year-1,x.month,x.day),data['report_date'])==data['date_1y_ago']] company_id signal_code_x signal_value_x report_date signal_code_y signal_value_y report_date_last date_1y_ago0 2154888 r_1002030000 0.62660 2015-09-30 r_1002030000 0.64145 2015-12-31 2014-12-311 2154888 r_1002030000 0.64145 2015-12-31 r_1002030000 0.64145 2015-12-31 2014-12-312 2154888 r_1002030000 0.60544 2015-03-31 r_1002030000 0.64145 2015-12-31 2014-12-313 2154888 r_1002030000 0.54911 2014-12-31 r_1002030000 0.64145 2015-12-31 2014-12-314 2154888 r_1002030000 0.61379 2015-06-30 r_1002030000 0.64145 2015-12-31 2014-12-315 1702887 r_1002030000 0.62173 2014-03-31 r_1002030000 0.51103 2015-03-31 2014-03-316 1702887 r_1002030000 0.55175 2014-12-31 r_1002030000 0.51103 2015-03-31 2014-03-317 1702887 r_1002030000 0.51103 2015-03-31 r_1002030000 0.51103 2015-03-31 2014-03-318 1702887 r_1002030000 0.58696 2014-06-30 r_1002030000 0.51103 2015-03-31 2014-03-319 13484491 r_1002030000 0.17658 2014-12-31 r_1002030000 0.41082 2015-12-31 2014-12-3110 13484491 r_1002030000 0.41082 2015-12-31 r_1002030000 0.41082 2015-12-31 2014-12-3111 13484491 r_1002030000 0.39220 2015-09-30 r_1002030000 0.41082 2015-12-31 2014-12-31
筛选后的数据:
company_id signal_code_x signal_value_x report_date signal_code_y signal_value_y report_date_last date_1y_ago1 2154888 r_1002030000 0.64145 2015-12-31 r_1002030000 0.64145 2015-12-31 2014-12-317 1702887 r_1002030000 0.51103 2015-03-31 r_1002030000 0.51103 2015-03-31 2014-03-3110 13484491 r_1002030000 0.41082 2015-12-31 r_1002030000 0.41082 2015-12-31 2014-12-31
以上这篇使用Python的Dataframe取两列时间值相差一年的所有行方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林站长站。
新闻热点
疑难解答