
[英]How to convert pandas df to dictionary with lists nested in the list?
[英]Convert dictionary to pandas df with values being lists of numbers while keeping list format
有一個看起來像這樣的字典:
opt = {
red: [28, 30, 32],
blue: [30],
green: [28, 32, 34, 38]
}
我希望將其轉換為 pandas dataframe ,如下所示:
| size | color |
| -------- | -------------- |
| sml | [red, blue, green] |
| med | [red] |
| lrg | [red, blue, green, orange] |
有什么方法可以輕松做到這一點?
df = pd.DataFrame( { 'color':[x for x in opt], 'rgb':[ opt[x] for x in opt] } )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.