Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing python sub list to import into pandas DataFrame
    text
    copied!<p>I'm trying to import fantasy basketball data from <a href="http://yuilibrary.com/yui/docs/yql/" rel="nofollow">yql</a> into a pandas data frame, but I'm running into issues with the nested content.</p> <p>The data from yql (results.rows) looks like this (when I use type(results.rows) I get list).</p> <pre><code>{u'display_position': u'PF', u'editorial_player_key': u'nba.p.4175', u'editorial_team_abbr': u'Uta', u'editorial_team_full_name': u'Utah Jazz', u'editorial_team_key': u'nba.t.26', u'eligible_positions': {u'position': u'PF'}, u'headshot': {u'size': u'small', u'url': u'http://l.yimg.com/iu/api/res/1.2/KjAPlP83IIrP9iReWfjyjw--/YXBwaWQ9eXZpZGVvO2NoPTIxNTtjcj0xO2N3PTE2NDtkeD0xO2R5PTE7Zmk9dWxjcm9wO2g9NjA7cT0xMDA7dz00Ng--/http://l.yimg.com/a/i/us/sp/v/nba/players_l/20101116/4175.jpg'}, u'image_url': u'http://l.yimg.com/iu/api/res/1.2/KjAPlP83IIrP9iReWfjyjw--/YXBwaWQ9eXZpZGVvO2NoPTIxNTtjcj0xO2N3PTE2NDtkeD0xO2R5PTE7Zmk9dWxjcm9wO2g9NjA7cT0xMDA7dz00Ng--/http://l.yimg.com/a/i/us/sp/v/nba/players_l/20101116/4175.jpg', u'is_undroppable': u'0', u'name': {u'ascii_first': u'Paul', u'ascii_last': u'Millsap', u'first': u'Paul', u'full': u'Paul Millsap', u'last': u'Millsap'}, u'player_id': u'4175', u'player_key': u'304.p.4175', u'position_type': u'P', u'uniform_number': u'24'} </code></pre> <p>When I perform </p> <pre><code>DataFrame(results.rows) </code></pre> <p>it imports the data fine, however the data in both headshot and name are imported as columns with their nested lists.</p> <p>I can access the sublist from iPython, however when I try to import it into a dataframe I get an error:</p> <pre><code>results[0]['name'] {u'ascii_first': u'Pau', u'ascii_last': u'Gasol', u'first': u'Pau', u'full': u'Pau Gasol', u'last': u'Gasol'} DataFrame([results[0]['name']) ValueError: If use all scalar values, must pass index </code></pre> <p>The behaviour that I want is to import the nested lists as their own columns rather than as a column containing the nested list. How can I do this?</p> <p>The end result that I would like is for a DataFrame with the following layout:</p> <pre><code>+---------------------------------------------------------------------------------------+ |display_position | (...) | ascii_first | ascii_last | first | full | last | player_id | +---------------------------------------------------------------------------------------+ | Data | | | | | | | | +---------------------------------------------------------------------------------------+ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload