0

I have a dataframe from excel spreadsheet in which I have found the frequency that each domain occurs. I want to add domain frequency count to it's corresponding domain.

     index   domain        extractor       Frequency
      0       linkedin.com  skipped            2
      1       facebook.com  skipped            5
      2       hi5.com       skipped            1 
      ....

Here is the code for finding the frequency and attempting to add it to the corresponding domain.

cnt = Counter()  

for row_index, row in df.iterrows():

    cnt[row['domain']] += 1

    for i in cnt:
        frequency = cnt

        if i in row['domain']:
            df['Frequency'] = df.loc[:(cnt[i])]

When I print out the frequency from the dataframe:

Index    url                                                   Frequency  
 0       https://www.linkedin.com/in/dgerstenblatt                 0  
 1       http://www.linkedin.com/in/darren-cfbs-5465872            1  
 2       http://www.hi5.com/friend/p39168004--profile--...         2  
 3       http://license.reg.state.ma.us/pubLic/pubLicen...         3  
 4       http://license.reg.state.ma.us/pubLic/pubLicen...         4  
 5       http://profiles.friendster.com/3523606                    5  
 6       http://www.lenoxadvisors.com/biographies/darre...       NaN  
 7       http://10digits.us/n/Darren_Gerstenblatt/Newto...       NaN  
 8       http://www.facebook.com/people/_/692786728              NaN  
pproctor
  • 101
  • 1
  • 10

1 Answers1

0

As Nehal posted, this is the correct solution. stackoverflow.com/q/22391433/1005215

pproctor
  • 101
  • 1
  • 10