Every line of 'pandas row to dict' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
323 def row2dict(row): 324 d = OrderedDict() 325 for column in row.__table__.columns: 326 d[column.name] = getattr(row, column.name) 327 328 return d
70 def to_dict(all_rows): 71 res = [] 72 for row in all_rows: 73 params = {item[0]: item[1] for item in list(zip(row.keys(), row))} 74 res.append(params) 75 return res
155 def row2dict(row): 156 """ 157 Converts a database-object to a python dict. 158 This function can be used to serialize an object into JSON, as this cannot be 159 directly done (but a dict can). 160 :param row: any object 161 :return: a python dict 162 """ 163 d = {} 164 for column in row.__table__.columns: 165 d[column.name] = str(getattr(row, column.name)) 166 167 return d
1006 def _db_row_to_dict(row, remove_columns=False): 1007 """Converts a DB object to a dictionary.""" 1008 1009 from sqlalchemy.inspection import inspect as sa_inspect 1010 from sqlalchemy.ext.hybrid import hybrid_property 1011 1012 row_dict = collections.OrderedDict() 1013 1014 columns = row.__table__.columns.keys() 1015 1016 mapper = sa_inspect(row.__class__) 1017 for key, item in mapper.all_orm_descriptors.items(): 1018 1019 if isinstance(item, hybrid_property): 1020 columns.append(key) 1021 1022 for col in columns: 1023 if remove_columns and col in remove_columns: 1024 continue 1025 row_dict[col] = getattr(row, col) 1026 1027 return row_dict