[英]hvplot interactive pd.DataFrame with multiIndex
我想從帶有 multiIndex 的 pd.DataFrame 創建一個交互式 hv.plot。
當我嘗試使我的數據框與 df.interactive 交互時,我收到錯誤消息:
Supplied data does not contain specified dimensions, the following dimensions were not found: ['fu', 'fu', 'bar', 'bar']
PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html
這是到目前為止的代碼
dictionary = {('fu', 'A'):[12,13,14,15],
('fu', 'B'):[17,18,19,20],
('bar', 'A'):[35,36,37,38],
('bar', 'B'):[45,46,47,48]}
df = pd.DataFrame(dictionary, index=[1,2,3,4])
那是我想繪制的數據框,給我以下輸出:
fu bar
A B A B
1 12 17 35 45
2 13 18 36 46
3 14 19 37 47
4 15 20 38 48
任何想法如何從這里繼續?
IIUC 你可以在調用 hvplot 方法之前展平列(將兩列級別減少到一個簡單的索引):
df_flat = df.set_axis(map(" ".join, df.columns), axis=1)
print(df_flat)
# output:
# fu A fu B bar A bar B
# 1 12 17 35 45
# 2 13 18 36 46
# 3 14 19 37 47
# 4 15 20 38 48
df_flat.interactive()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.