title: KeyError: ('count', 'occurred at index 0')
body: <p>I am trying to do the example in <a href="http://www.austintaylor.io/d3/python/pandas/2016/02/01/create-d3-chart-python-force-directed/" rel="noreferrer">Use Python &amp; Pandas to Create a D3 Force Directed Network Diagram</a></p>
  
  <p>But in the below line I am getting an error 'KeyError: ('count', 'occurred at index 0')'</p>
  
  <pre><code> temp_links_list = list(grouped_src_dst.apply(lambda row: {"source": row['source'], "target": row['target'], "value": row['count']}, axis=1))
  </code></pre>
  
  <p>I am new in python. What is the issue here?</p>
  
  <p><strong>Edited code</strong></p>
  
  <pre><code>import pandas as pd
  import json
  import re
  
  pcap_data = pd.read_csv('C:\packet_metadata.csv', index_col='No.')
  dataframe = pcap_data
  src_dst = dataframe[["Source","Destination"]]
  src_dst.rename(columns={"Source":"source","Destination":"target"}, inplace=True)
  grouped_src_dst = src_dst.groupby(["source","target"]).size().reset_index()
  grouped_src_dst.rename(columns={'count':'value'}).to_dict(orient='records')
  unique_ips = pd.Index(grouped_src_dst['source']
                    .append(grouped_src_dst['target'])
                    .reset_index(drop=True).unique())
  </code></pre>
  
  <p>But     </p>
  
  <pre><code>print(grouped_src_dst.columns.tolist())
  ['source', 'target', 0]
  </code></pre>
  
  <p><strong>Final code</strong></p>
  
  <pre><code>import pandas as pd
  import json
  import re
  
  pcap_data = pd.read_csv('C:\packet_metadata.csv', index_col='No.')
  dataframe = pcap_data
  src_dst = dataframe[["Source","Destination"]]
  src_dst.sample(10)
  grouped_src_dst = src_dst.groupby(["Source","Destination"]).size().reset_index()
  d={0:'value',"Source":"source","Destination":"target"}
  L = grouped_src_dst.rename(columns=d)
  unique_ips = pd.Index(L['source']
                    .append(L['target'])
                    .reset_index(drop=True).unique())
  group_dict = {}
  counter = 0
  for ip in unique_ips:
  breakout_ip = re.match("^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip)
  if breakout_ip:
      net_id = '.'.join(breakout_ip.group(1,2,3))
      if net_id not in group_dict:
          counter += 1
          group_dict[net_id] = counter
      else:
          pass
  
  
  temp_links_list = list(L.apply(lambda row: {"source": row['source'], "target": row['target'], "value": row['value']}, axis=1))
  </code></pre>