python 二维元祖关联合并 返回列表
来源:互联网 发布:万维网域名续费 编辑:程序博客网 时间:2024/05/17 23:08
# -*- coding: utf-8 -*-import pandas as pdimport numpy as npimport loggingimport tracebackclass concat_tuples_to_list(): def __init__(self): pass # tuples = {tuple1, tuple2} # headers = {header1, header2} def concat_datasrcset(self,tuples, headers, condkey): result = {} try: if not tuples and not headers: result = {'errorcode':-1, 'errortext':'tuples or headers is not invalid'} return result header1 = headers['header1'] header2 = headers['header2'] if (condkey not in header1) and (condkey not in header2): result['errorcode'] = -1 result['errortext'] = '%s is not in %s' % (condkey, headers) return result list1 = list(tuples['tuple1']) list2 = list(tuples['tuple2']) list1[:] = [list(t) for t in list1] list2[:] = [list(t) for t in list2] df1 = pd.DataFrame(list1, columns=header1) df2 = pd.DataFrame(list2, columns=header2) #合并二维列表 df3 = pd.merge(df1, df2, how='left', on=condkey) df3 = df3.where(df3.notnull(), None) train_data = np.array(df3) result['datasrcset'] = train_data.tolist() result['errorcode'] = 0 return result except Exception, ex: result['errorcode'] = -1 result['errortext'] = '%s_%s:%s' % (traceback.print_exc(), Exception, ex) logging.error(result) return result
阅读全文
0 0
- python 二维元祖关联合并 返回列表
- Python-列表和元祖
- python功能二维表合并,一维表内嵌元祖合并以及取交集,并集,差集
- python 元祖,列表,字典 初识
- Python中的列表、元祖、字典
- Python字符串,元祖,列表,字典
- python之列表和元祖
- python 基础知识(列表 元祖)
- python中的列表与元祖
- python序列操作--元祖,列表
- python系列之列表和元祖
- Python列表,元祖及字典的区别
- Python元祖,列表,字典,集合的比较
- python入门--列表list和元祖tuple
- Python元祖,列表,字典,集合的比较
- 20161011 Python 读书笔记之 列表、元祖、字典
- python中元祖,列表,字典的区别
- python的元祖。字典,列表的区别
- Ubuntu mysql 报错:MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- Linux 信号以及开发中常见信号错误
- 国税北京开发票流程
- 新手搭建ssm框架
- 第一篇文章
- python 二维元祖关联合并 返回列表
- 好用的Chrome扩展插件推荐集合,性能提升,效率提高!
- 时间取值问题(BCB)
- django 分享
- 23种设计模式 创建类模式 (1) 单例模式
- hhtp状态码
- springmvc和struts2的区别
- SOA,Web Service,SOAP,REST,RPC,RMI,JMS的区别与联系
- c++ crash日志