panda dataframe iterate and adding to set issue
<p>I have a dataframe that looks like this:</p>

<pre><code>                name
0   [somename1, somename2, n...
1   [name1, someothername, ...
2   [name, name, s...
3   [somename1, name3, s...
4   [name2, name2, s...
5   [somename2, name2, s...
6   [somename1, somename, s...
</code></pre>

<p>I am trying to iterate through the dataframe and save the data in the dataframe as a sequence in a set. 
Therefore I have done this:</p>

<pre><code>events = set([])

for index, row in datarame.iterrows():
    session = row['name']
    print len(session)
    for x in session:
        events.add(x)

print events length total: 
print len(events)
</code></pre>

<p>What I get as an output here is:</p>

<pre><code>    24
    80
    15
    60
    76
    66
    83
    32
    100
    73
    13
    3
    2
    9
    57
    2
    2
    4
    1
    events length total:
    108
</code></pre>

<p>Which does not make sense. Normally it should add all the contents in the sessions and the length should be the summary of the numbers above, which obviously is not.</p>

<p>A <code>set</code> in python is an </p>

<blockquote>
  <p>unordered collection of <strong>unique</strong> elements.</p>
</blockquote>

<p>It does not allow duplicates.</p>

<p>You should define <code>event</code> as a <code>list</code> instead.</p>

<pre><code>events = []

for index, row in datarame.iterrows():
    session = row['name']
    print len(session)
    for x in session:
        events.append(x)

print events length total: 
print len(events)
</code></pre>

python dataframe set iteration