python, dictionary in a data frame, sorting
<p>I have a python data frame called wiki, with the wikipedia information for some people. 
Each row is a different person, and the columns are : 'name', 'text' and 'word_count'. The information in 'text' has been put in dictionary form (keys,values), to create the information in the column 'word_count'.</p>

<p>If I want to extract the row related to Barack Obama, then:</p>

<pre><code>row = wiki[wiki['name'] == 'Barack Obama']
</code></pre>

<p>Now, I would like the most popular word. When I do:</p>

<pre><code>adf=row[['word_count']]
</code></pre>

<p>I get another data frame because I see that:</p>

<pre><code>type(adf)=&lt;class 'pandas.core.frame.DataFrame'&gt;
</code></pre>

<p>and if I do </p>

<pre><code>adf.values
</code></pre>

<p>I get:</p>

<pre><code>array([[ {u'operations': 1, u'represent': 1, u'office': 2, ..., u'began': 1}], dtype=object)
</code></pre>

<p>However, what is very confusing to me is that the size is 1</p>

<pre><code>adf.size=1
</code></pre>

<p>Therefore, I do not know how to actually extract the keys and values. Things like <code>adf.values[1]</code> do not work</p>

<p>Ultimately, what I need to do is sort the information in word_count so that the most frequent words appear first.
But I would like to understand how to access a the information that is inside a dictionary, inside a data frame... I am lost about the types here. I am not new to programming, but I am relatively new to python.</p>

<p>Any help would be very very much appreciated</p>

<p>If the name column is unique, then you can change the column to the index of the <code>DataFrame</code> object:<code>wiki.set_index("name", inplace=True)</code>. Then you can get the value by: <code>wiki.at['Barack Obama', 'word_count']</code>.</p>

<p>With your code:</p>

<pre><code>row = wiki[wiki['name'] == 'Barack Obama']
adf = row[['word_count']]
</code></pre>

<p>The first line use a bool array to get the data, here is the document: <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing</a></p>

<p><code>wiki</code> is a <code>DataFrame</code> object, and <code>row</code> is also a <code>DataFrame</code> object with only one row, if the name column is unique.</p>

<p>The second line get a list of columns from the <code>row</code>, here is the document: <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#basics" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/indexing.html#basics</a></p>

<p>You get a <code>DataFrame</code> with only one row and one column.</p>

<p>And here is the document of <code>.at[]</code>: <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#fast-scalar-value-getting-and-setting" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/indexing.html#fast-scalar-value-getting-and-setting</a></p>

python sorting pandas dictionary dataframe