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;
}
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
add a comment |
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
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
add a comment |
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
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
python python-3.x pandas
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
amazing, thanks a lot. It works super well
– Giangi
Nov 16 '18 at 12:04
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
amazing, thanks a lot. It works super well
– Giangi
Nov 16 '18 at 12:04
add a comment |
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
amazing, thanks a lot. It works super well
– Giangi
Nov 16 '18 at 12:04
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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