use*_*988 7 python datetime time-series pandas
我试图使用以下代码连接100个具有2个日期时间索引的数据帧:
concat_df = pd.concat([df_dict[c] for c in df_dict], axis = 1)
Run Code Online (Sandbox Code Playgroud)
但是其中一个数据帧(我假设它是一个但可能更多)导致发生以下异常:
Exception: cannot handle a non-unique multi-index!
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
它是指第一个索引还是第二个索引?
我发现它指的是我的解决方案的第一个索引:(认为不确定它的效率如何,但随后 concat 起作用)
dup_first_index_dates = np.where(np.array([np.sum(df_dict[c].index.duplicated()) for c in df_dict]) == 1)[0]
key = df_dict.keys()
for i in dup_first_index_dates :
df_dict[key[i]] = df_dict[tickers[i]].reset_index().drop_duplicates('Level1').set_index(['Level1', 'Level2'])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7986 次 |
| 最近记录: |