Pandas DataFrame from list of dicts (couldnt find this config)












-2















from the following list of dicts



 d=[{u'identifier': u'AAPL', u'item': u'beta', u'value': 1.0448},
{u'identifier': u'GOOG', u'item': u'three_yr_weekly_beta', u'value': 1.2656},
{u'identifier': u'AAPL', u'item': u'legal_name', u'value': u'APPLE INC'},
{u'identifier': u'GOOG', u'item': u'legal_name', u'value': u'Alphabet Inc.'},
{u'identifier': u'AAPL',u'item': u'market_category',u'value': u'Common Stock'}]


I was able to get as far as



df = pd.DataFrame.from_records(d, index='item')


i would like for the columns to be the 'identifier' (AAPL and GOOG) rather than 'identifier' and 'value'










share|improve this question

























  • try, df = pd.DataFrame.from_records(d).set_index(['item', 'value'])

    – has
    Nov 14 '18 at 12:38











  • Post your desired output please.

    – timgeb
    Nov 14 '18 at 12:38
















-2















from the following list of dicts



 d=[{u'identifier': u'AAPL', u'item': u'beta', u'value': 1.0448},
{u'identifier': u'GOOG', u'item': u'three_yr_weekly_beta', u'value': 1.2656},
{u'identifier': u'AAPL', u'item': u'legal_name', u'value': u'APPLE INC'},
{u'identifier': u'GOOG', u'item': u'legal_name', u'value': u'Alphabet Inc.'},
{u'identifier': u'AAPL',u'item': u'market_category',u'value': u'Common Stock'}]


I was able to get as far as



df = pd.DataFrame.from_records(d, index='item')


i would like for the columns to be the 'identifier' (AAPL and GOOG) rather than 'identifier' and 'value'










share|improve this question

























  • try, df = pd.DataFrame.from_records(d).set_index(['item', 'value'])

    – has
    Nov 14 '18 at 12:38











  • Post your desired output please.

    – timgeb
    Nov 14 '18 at 12:38














-2












-2








-2








from the following list of dicts



 d=[{u'identifier': u'AAPL', u'item': u'beta', u'value': 1.0448},
{u'identifier': u'GOOG', u'item': u'three_yr_weekly_beta', u'value': 1.2656},
{u'identifier': u'AAPL', u'item': u'legal_name', u'value': u'APPLE INC'},
{u'identifier': u'GOOG', u'item': u'legal_name', u'value': u'Alphabet Inc.'},
{u'identifier': u'AAPL',u'item': u'market_category',u'value': u'Common Stock'}]


I was able to get as far as



df = pd.DataFrame.from_records(d, index='item')


i would like for the columns to be the 'identifier' (AAPL and GOOG) rather than 'identifier' and 'value'










share|improve this question
















from the following list of dicts



 d=[{u'identifier': u'AAPL', u'item': u'beta', u'value': 1.0448},
{u'identifier': u'GOOG', u'item': u'three_yr_weekly_beta', u'value': 1.2656},
{u'identifier': u'AAPL', u'item': u'legal_name', u'value': u'APPLE INC'},
{u'identifier': u'GOOG', u'item': u'legal_name', u'value': u'Alphabet Inc.'},
{u'identifier': u'AAPL',u'item': u'market_category',u'value': u'Common Stock'}]


I was able to get as far as



df = pd.DataFrame.from_records(d, index='item')


i would like for the columns to be the 'identifier' (AAPL and GOOG) rather than 'identifier' and 'value'







python pandas dataframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 13:30









Malik Asad

296111




296111










asked Nov 14 '18 at 12:34









wlbsrwlbsr

82




82













  • try, df = pd.DataFrame.from_records(d).set_index(['item', 'value'])

    – has
    Nov 14 '18 at 12:38











  • Post your desired output please.

    – timgeb
    Nov 14 '18 at 12:38



















  • try, df = pd.DataFrame.from_records(d).set_index(['item', 'value'])

    – has
    Nov 14 '18 at 12:38











  • Post your desired output please.

    – timgeb
    Nov 14 '18 at 12:38

















try, df = pd.DataFrame.from_records(d).set_index(['item', 'value'])

– has
Nov 14 '18 at 12:38





try, df = pd.DataFrame.from_records(d).set_index(['item', 'value'])

– has
Nov 14 '18 at 12:38













Post your desired output please.

– timgeb
Nov 14 '18 at 12:38





Post your desired output please.

– timgeb
Nov 14 '18 at 12:38












1 Answer
1






active

oldest

votes


















0














I think you need pivoting:



df = pd.DataFrame(d).pivot('item','identifier','value')
#alternative solution
#df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()




print (df)
identifier AAPL GOOG
item
beta 1.0448 NaN
legal_name APPLE INC Alphabet Inc.
market_category Common Stock NaN
three_yr_weekly_beta NaN 1.2656





share|improve this answer
























  • this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

    – wlbsr
    Nov 14 '18 at 13:02













  • @wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

    – jezrael
    Nov 14 '18 at 13:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300371%2fpandas-dataframe-from-list-of-dicts-couldnt-find-this-config%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think you need pivoting:



df = pd.DataFrame(d).pivot('item','identifier','value')
#alternative solution
#df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()




print (df)
identifier AAPL GOOG
item
beta 1.0448 NaN
legal_name APPLE INC Alphabet Inc.
market_category Common Stock NaN
three_yr_weekly_beta NaN 1.2656





share|improve this answer
























  • this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

    – wlbsr
    Nov 14 '18 at 13:02













  • @wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

    – jezrael
    Nov 14 '18 at 13:02
















0














I think you need pivoting:



df = pd.DataFrame(d).pivot('item','identifier','value')
#alternative solution
#df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()




print (df)
identifier AAPL GOOG
item
beta 1.0448 NaN
legal_name APPLE INC Alphabet Inc.
market_category Common Stock NaN
three_yr_weekly_beta NaN 1.2656





share|improve this answer
























  • this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

    – wlbsr
    Nov 14 '18 at 13:02













  • @wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

    – jezrael
    Nov 14 '18 at 13:02














0












0








0







I think you need pivoting:



df = pd.DataFrame(d).pivot('item','identifier','value')
#alternative solution
#df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()




print (df)
identifier AAPL GOOG
item
beta 1.0448 NaN
legal_name APPLE INC Alphabet Inc.
market_category Common Stock NaN
three_yr_weekly_beta NaN 1.2656





share|improve this answer













I think you need pivoting:



df = pd.DataFrame(d).pivot('item','identifier','value')
#alternative solution
#df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()




print (df)
identifier AAPL GOOG
item
beta 1.0448 NaN
legal_name APPLE INC Alphabet Inc.
market_category Common Stock NaN
three_yr_weekly_beta NaN 1.2656






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 12:40









jezraeljezrael

333k24274351




333k24274351













  • this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

    – wlbsr
    Nov 14 '18 at 13:02













  • @wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

    – jezrael
    Nov 14 '18 at 13:02



















  • this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

    – wlbsr
    Nov 14 '18 at 13:02













  • @wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

    – jezrael
    Nov 14 '18 at 13:02

















this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

– wlbsr
Nov 14 '18 at 13:02







this is the only thing that I could get to work : df = pd.DataFrame(d).set_index(['item','identifier'])['value'].unstack()

– wlbsr
Nov 14 '18 at 13:02















@wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

– jezrael
Nov 14 '18 at 13:02





@wlbsr - You are welcome! If my answer was helpful, don't forget accept it. Thanks.

– jezrael
Nov 14 '18 at 13:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300371%2fpandas-dataframe-from-list-of-dicts-couldnt-find-this-config%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python