How to split in Pandas cells with multiple data





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm trying to extract data from this output (multiplied by 23 col but i will do on a post basis):



                         0                                                                                             22
2014 {'tag': 'operatingrevenue', 'value': 182795000}

[1 rows x 23 columns]


How can I extract in order to have a table, indexed by years, with the columns populated with the 'tag' and the values as the relative value of that tag?



     |   operatingrevenue   

2014 | 182795000


I specify that i'm working with pandas and python 3.7



Thanks










share|improve this question




















  • 1





    what's your expected output?

    – AkshayNevrekar
    Nov 16 '18 at 11:24






  • 1





    Could you update your question with an example dataframe, so that we can help.

    – Philip
    Nov 16 '18 at 11:24











  • Done, thanks a lot to everyone. I'm struggling since 2 days, i tried to do it on my own but i don't know what to look for.

    – Giangi
    Nov 16 '18 at 11:40











  • That original sample data isnt very clear. can you update?

    – MEdwin
    Nov 16 '18 at 11:42











  • It should be clearer now. I have 23 columns but i will work on those with a loop.

    – Giangi
    Nov 16 '18 at 11:51


















1















I'm trying to extract data from this output (multiplied by 23 col but i will do on a post basis):



                         0                                                                                             22
2014 {'tag': 'operatingrevenue', 'value': 182795000}

[1 rows x 23 columns]


How can I extract in order to have a table, indexed by years, with the columns populated with the 'tag' and the values as the relative value of that tag?



     |   operatingrevenue   

2014 | 182795000


I specify that i'm working with pandas and python 3.7



Thanks










share|improve this question




















  • 1





    what's your expected output?

    – AkshayNevrekar
    Nov 16 '18 at 11:24






  • 1





    Could you update your question with an example dataframe, so that we can help.

    – Philip
    Nov 16 '18 at 11:24











  • Done, thanks a lot to everyone. I'm struggling since 2 days, i tried to do it on my own but i don't know what to look for.

    – Giangi
    Nov 16 '18 at 11:40











  • That original sample data isnt very clear. can you update?

    – MEdwin
    Nov 16 '18 at 11:42











  • It should be clearer now. I have 23 columns but i will work on those with a loop.

    – Giangi
    Nov 16 '18 at 11:51














1












1








1








I'm trying to extract data from this output (multiplied by 23 col but i will do on a post basis):



                         0                                                                                             22
2014 {'tag': 'operatingrevenue', 'value': 182795000}

[1 rows x 23 columns]


How can I extract in order to have a table, indexed by years, with the columns populated with the 'tag' and the values as the relative value of that tag?



     |   operatingrevenue   

2014 | 182795000


I specify that i'm working with pandas and python 3.7



Thanks










share|improve this question
















I'm trying to extract data from this output (multiplied by 23 col but i will do on a post basis):



                         0                                                                                             22
2014 {'tag': 'operatingrevenue', 'value': 182795000}

[1 rows x 23 columns]


How can I extract in order to have a table, indexed by years, with the columns populated with the 'tag' and the values as the relative value of that tag?



     |   operatingrevenue   

2014 | 182795000


I specify that i'm working with pandas and python 3.7



Thanks







python python-3.x pandas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 11:50







Giangi

















asked Nov 16 '18 at 11:20









GiangiGiangi

84




84








  • 1





    what's your expected output?

    – AkshayNevrekar
    Nov 16 '18 at 11:24






  • 1





    Could you update your question with an example dataframe, so that we can help.

    – Philip
    Nov 16 '18 at 11:24











  • Done, thanks a lot to everyone. I'm struggling since 2 days, i tried to do it on my own but i don't know what to look for.

    – Giangi
    Nov 16 '18 at 11:40











  • That original sample data isnt very clear. can you update?

    – MEdwin
    Nov 16 '18 at 11:42











  • It should be clearer now. I have 23 columns but i will work on those with a loop.

    – Giangi
    Nov 16 '18 at 11:51














  • 1





    what's your expected output?

    – AkshayNevrekar
    Nov 16 '18 at 11:24






  • 1





    Could you update your question with an example dataframe, so that we can help.

    – Philip
    Nov 16 '18 at 11:24











  • Done, thanks a lot to everyone. I'm struggling since 2 days, i tried to do it on my own but i don't know what to look for.

    – Giangi
    Nov 16 '18 at 11:40











  • That original sample data isnt very clear. can you update?

    – MEdwin
    Nov 16 '18 at 11:42











  • It should be clearer now. I have 23 columns but i will work on those with a loop.

    – Giangi
    Nov 16 '18 at 11:51








1




1





what's your expected output?

– AkshayNevrekar
Nov 16 '18 at 11:24





what's your expected output?

– AkshayNevrekar
Nov 16 '18 at 11:24




1




1





Could you update your question with an example dataframe, so that we can help.

– Philip
Nov 16 '18 at 11:24





Could you update your question with an example dataframe, so that we can help.

– Philip
Nov 16 '18 at 11:24













Done, thanks a lot to everyone. I'm struggling since 2 days, i tried to do it on my own but i don't know what to look for.

– Giangi
Nov 16 '18 at 11:40





Done, thanks a lot to everyone. I'm struggling since 2 days, i tried to do it on my own but i don't know what to look for.

– Giangi
Nov 16 '18 at 11:40













That original sample data isnt very clear. can you update?

– MEdwin
Nov 16 '18 at 11:42





That original sample data isnt very clear. can you update?

– MEdwin
Nov 16 '18 at 11:42













It should be clearer now. I have 23 columns but i will work on those with a loop.

– Giangi
Nov 16 '18 at 11:51





It should be clearer now. I have 23 columns but i will work on those with a loop.

– Giangi
Nov 16 '18 at 11:51












1 Answer
1






active

oldest

votes


















0














If this data is representative of your case, it should work:



import pandas as pd

df = pd.DataFrame({0: [{'tag': 'operatingrevenue', 'value': 182795000},
{'tag': 'operatingrevenue', 'value': 182796000}],
1: [{'tag': 'cashdividendspershare', 'value': 1.82},
{'tag': 'cashdividendspershare', 'value': 1.92}]},
index=[2014, 2015])

df.columns = [i['tag'] for i in df.iloc[0].values]

df = df.applymap(lambda x: x['value'])

df

operatingrevenue cashdividendspershare
2014 182795000 1.82
2015 182796000 1.92





share|improve this answer
























  • amazing, thanks a lot. It works super well

    – Giangi
    Nov 16 '18 at 12:04












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%2f53336848%2fhow-to-split-in-pandas-cells-with-multiple-data%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














If this data is representative of your case, it should work:



import pandas as pd

df = pd.DataFrame({0: [{'tag': 'operatingrevenue', 'value': 182795000},
{'tag': 'operatingrevenue', 'value': 182796000}],
1: [{'tag': 'cashdividendspershare', 'value': 1.82},
{'tag': 'cashdividendspershare', 'value': 1.92}]},
index=[2014, 2015])

df.columns = [i['tag'] for i in df.iloc[0].values]

df = df.applymap(lambda x: x['value'])

df

operatingrevenue cashdividendspershare
2014 182795000 1.82
2015 182796000 1.92





share|improve this answer
























  • amazing, thanks a lot. It works super well

    – Giangi
    Nov 16 '18 at 12:04
















0














If this data is representative of your case, it should work:



import pandas as pd

df = pd.DataFrame({0: [{'tag': 'operatingrevenue', 'value': 182795000},
{'tag': 'operatingrevenue', 'value': 182796000}],
1: [{'tag': 'cashdividendspershare', 'value': 1.82},
{'tag': 'cashdividendspershare', 'value': 1.92}]},
index=[2014, 2015])

df.columns = [i['tag'] for i in df.iloc[0].values]

df = df.applymap(lambda x: x['value'])

df

operatingrevenue cashdividendspershare
2014 182795000 1.82
2015 182796000 1.92





share|improve this answer
























  • amazing, thanks a lot. It works super well

    – Giangi
    Nov 16 '18 at 12:04














0












0








0







If this data is representative of your case, it should work:



import pandas as pd

df = pd.DataFrame({0: [{'tag': 'operatingrevenue', 'value': 182795000},
{'tag': 'operatingrevenue', 'value': 182796000}],
1: [{'tag': 'cashdividendspershare', 'value': 1.82},
{'tag': 'cashdividendspershare', 'value': 1.92}]},
index=[2014, 2015])

df.columns = [i['tag'] for i in df.iloc[0].values]

df = df.applymap(lambda x: x['value'])

df

operatingrevenue cashdividendspershare
2014 182795000 1.82
2015 182796000 1.92





share|improve this answer













If this data is representative of your case, it should work:



import pandas as pd

df = pd.DataFrame({0: [{'tag': 'operatingrevenue', 'value': 182795000},
{'tag': 'operatingrevenue', 'value': 182796000}],
1: [{'tag': 'cashdividendspershare', 'value': 1.82},
{'tag': 'cashdividendspershare', 'value': 1.92}]},
index=[2014, 2015])

df.columns = [i['tag'] for i in df.iloc[0].values]

df = df.applymap(lambda x: x['value'])

df

operatingrevenue cashdividendspershare
2014 182795000 1.82
2015 182796000 1.92






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 11:58









zipazipa

16.3k31738




16.3k31738













  • amazing, thanks a lot. It works super well

    – Giangi
    Nov 16 '18 at 12:04



















  • amazing, thanks a lot. It works super well

    – Giangi
    Nov 16 '18 at 12:04

















amazing, thanks a lot. It works super well

– Giangi
Nov 16 '18 at 12:04





amazing, thanks a lot. It works super well

– Giangi
Nov 16 '18 at 12:04




















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%2f53336848%2fhow-to-split-in-pandas-cells-with-multiple-data%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

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues