我有一本要轉換為 DataFrame 的字典,我遇到的問題是我的字典采用以下格式:
sample_dict = {'test':['test string',['feature1','feature2', 'feature3']]}
當嘗試使用類似的東西進行轉換時
df = pd.DataFrame.from_dict([sample_dict])
我得到:

我想要實作的是:

有任何想法嗎?
uj5u.com熱心網友回復:
添加orient
out = pd.DataFrame.from_dict(sample_dict, orient='index')
Out[287]:
0 1
test test string [feature1, feature2, feature3]
uj5u.com熱心網友回復:
也可以用from_records。
df = pd.DataFrame.from_records(d).T
0 1
test test string [feature1, feature2, feature3]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/525441.html
標籤:Python熊猫
