【发布时间】:2022-08-17 20:17:31
【问题描述】:
我有以下输入和用例,注意索引是数组,当len 大于一时,表示广播:
import pandas as pd
df = pd.DataFrame([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]],
index=pd.Index([[1], [2, 3], [4]]),
columns=[\'a\', \'b\', \'c\'])
print(df)
并希望以一种广播值的方式展平索引,如下所示:
expected = pd.DataFrame([[1, 2, 3],
[4, 5, 6],
[4, 5, 6],
[7, 8, 9]],
index=[1, 2, 3, 4],
columns=[\'a\', \'b\', \'c\'])
print(expected)