Extract data from a pandas series if the values are in a dictionary-like format
I try the solution in Extracting dictionary values from a pandas dataframe But it didn't work.
I have a pandas.core.series.Series with the following general format:
0 {'hashtags': , 'symbols': , 'user_mentions...
1 {'hashtags': , 'symbols': , 'user_mentions...
2 {'hashtags': , 'symbols': , 'user_mentions...
3 {'hashtags': , 'symbols': , 'user_mentions...
...
the specific format of each one is similar to the following:
{'hashtags': ,
'symbols': ,
'user_mentions': [{'screen_name': 'jose_m',
'id_str': '132',
'name': 'Jose',
'indices': [0, 10],
'id': 103},
{'screen_name': 'paul',
'id_str': '243403',
'name': 'Jorge',
'indices': [50, 64],
'id': 2423}],
'urls': }
I get that by placing the index zero to the variable entities[0]
(Index may change).
I need to extract extract all the screen_name and name inside user_mentions. Thanks :)
python pandas
add a comment |
I try the solution in Extracting dictionary values from a pandas dataframe But it didn't work.
I have a pandas.core.series.Series with the following general format:
0 {'hashtags': , 'symbols': , 'user_mentions...
1 {'hashtags': , 'symbols': , 'user_mentions...
2 {'hashtags': , 'symbols': , 'user_mentions...
3 {'hashtags': , 'symbols': , 'user_mentions...
...
the specific format of each one is similar to the following:
{'hashtags': ,
'symbols': ,
'user_mentions': [{'screen_name': 'jose_m',
'id_str': '132',
'name': 'Jose',
'indices': [0, 10],
'id': 103},
{'screen_name': 'paul',
'id_str': '243403',
'name': 'Jorge',
'indices': [50, 64],
'id': 2423}],
'urls': }
I get that by placing the index zero to the variable entities[0]
(Index may change).
I need to extract extract all the screen_name and name inside user_mentions. Thanks :)
python pandas
add a comment |
I try the solution in Extracting dictionary values from a pandas dataframe But it didn't work.
I have a pandas.core.series.Series with the following general format:
0 {'hashtags': , 'symbols': , 'user_mentions...
1 {'hashtags': , 'symbols': , 'user_mentions...
2 {'hashtags': , 'symbols': , 'user_mentions...
3 {'hashtags': , 'symbols': , 'user_mentions...
...
the specific format of each one is similar to the following:
{'hashtags': ,
'symbols': ,
'user_mentions': [{'screen_name': 'jose_m',
'id_str': '132',
'name': 'Jose',
'indices': [0, 10],
'id': 103},
{'screen_name': 'paul',
'id_str': '243403',
'name': 'Jorge',
'indices': [50, 64],
'id': 2423}],
'urls': }
I get that by placing the index zero to the variable entities[0]
(Index may change).
I need to extract extract all the screen_name and name inside user_mentions. Thanks :)
python pandas
I try the solution in Extracting dictionary values from a pandas dataframe But it didn't work.
I have a pandas.core.series.Series with the following general format:
0 {'hashtags': , 'symbols': , 'user_mentions...
1 {'hashtags': , 'symbols': , 'user_mentions...
2 {'hashtags': , 'symbols': , 'user_mentions...
3 {'hashtags': , 'symbols': , 'user_mentions...
...
the specific format of each one is similar to the following:
{'hashtags': ,
'symbols': ,
'user_mentions': [{'screen_name': 'jose_m',
'id_str': '132',
'name': 'Jose',
'indices': [0, 10],
'id': 103},
{'screen_name': 'paul',
'id_str': '243403',
'name': 'Jorge',
'indices': [50, 64],
'id': 2423}],
'urls': }
I get that by placing the index zero to the variable entities[0]
(Index may change).
I need to extract extract all the screen_name and name inside user_mentions. Thanks :)
python pandas
python pandas
asked Nov 23 '18 at 1:48
Ricardo PrietoRicardo Prieto
154
154
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Here is an example with apply, for each entities
returns a list with a tuple for each user_mention
:
def find_user_mention(user_mention):
return (user_mention['screen_name'], user_mention['name'])
df['entities'].apply(lambda x: [find_user_mention(user_mention) for user_mention in x['user_mentions']])
Example output with random data:
0 [(NunkMasKKs, 🍣 SUSHIPLANERO 🍣)]
1 [(leobilanski, Leo Bilanski)]
2 [(romerodiario, El Profe Romero)]
3 [(HugoYasky, Hugo Yasky)]
4 [(marianorecalde, Mariano Recalde)]
5 [(cyngarciaradio, Cynthia García)]
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
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%2f53439773%2fextract-data-from-a-pandas-series-if-the-values-are-in-a-dictionary-like-format%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
Here is an example with apply, for each entities
returns a list with a tuple for each user_mention
:
def find_user_mention(user_mention):
return (user_mention['screen_name'], user_mention['name'])
df['entities'].apply(lambda x: [find_user_mention(user_mention) for user_mention in x['user_mentions']])
Example output with random data:
0 [(NunkMasKKs, 🍣 SUSHIPLANERO 🍣)]
1 [(leobilanski, Leo Bilanski)]
2 [(romerodiario, El Profe Romero)]
3 [(HugoYasky, Hugo Yasky)]
4 [(marianorecalde, Mariano Recalde)]
5 [(cyngarciaradio, Cynthia García)]
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
add a comment |
Here is an example with apply, for each entities
returns a list with a tuple for each user_mention
:
def find_user_mention(user_mention):
return (user_mention['screen_name'], user_mention['name'])
df['entities'].apply(lambda x: [find_user_mention(user_mention) for user_mention in x['user_mentions']])
Example output with random data:
0 [(NunkMasKKs, 🍣 SUSHIPLANERO 🍣)]
1 [(leobilanski, Leo Bilanski)]
2 [(romerodiario, El Profe Romero)]
3 [(HugoYasky, Hugo Yasky)]
4 [(marianorecalde, Mariano Recalde)]
5 [(cyngarciaradio, Cynthia García)]
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
add a comment |
Here is an example with apply, for each entities
returns a list with a tuple for each user_mention
:
def find_user_mention(user_mention):
return (user_mention['screen_name'], user_mention['name'])
df['entities'].apply(lambda x: [find_user_mention(user_mention) for user_mention in x['user_mentions']])
Example output with random data:
0 [(NunkMasKKs, 🍣 SUSHIPLANERO 🍣)]
1 [(leobilanski, Leo Bilanski)]
2 [(romerodiario, El Profe Romero)]
3 [(HugoYasky, Hugo Yasky)]
4 [(marianorecalde, Mariano Recalde)]
5 [(cyngarciaradio, Cynthia García)]
Here is an example with apply, for each entities
returns a list with a tuple for each user_mention
:
def find_user_mention(user_mention):
return (user_mention['screen_name'], user_mention['name'])
df['entities'].apply(lambda x: [find_user_mention(user_mention) for user_mention in x['user_mentions']])
Example output with random data:
0 [(NunkMasKKs, 🍣 SUSHIPLANERO 🍣)]
1 [(leobilanski, Leo Bilanski)]
2 [(romerodiario, El Profe Romero)]
3 [(HugoYasky, Hugo Yasky)]
4 [(marianorecalde, Mariano Recalde)]
5 [(cyngarciaradio, Cynthia García)]
answered Nov 23 '18 at 2:36
LucasLucas
2,35211128
2,35211128
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
add a comment |
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
Great! thank you very much
– Ricardo Prieto
Nov 23 '18 at 2:50
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%2f53439773%2fextract-data-from-a-pandas-series-if-the-values-are-in-a-dictionary-like-format%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