Handling Duplicate Columns in Pandas DataFrame constructor from SQLAlchemy Join
我知道
1 | pd.DataFrame(result.fetchall(), columns=result.keys()) |
由于使用了重复的col名称,因此在使用
您可以创建自己的帮助程序功能来处理列名。 我从
1 2 3 4 5 6 7 8 9 10 | def mangle_dupe_cols(columns): counts = {} for i, col in enumerate(columns): cur_count = counts.get(col, 0) if cur_count > 0: columns[i] = '%s.%d' % (col, cur_count) counts[col] = cur_count + 1 return columns pd.DataFrame(result.fetchall(), columns=mangle_dupe_cols(result.keys())) |