python i have error in nonetype how to slove it

Posted on 2018-03-13
Low Priority
Last Modified: 2018-03-13
python i have error in nonetype how to slove it

Here i am trying to get domain names of the companies and the company names are stored in new.csv  

**The code i have used**  

    import pandas as pd
    import clearbit
    import json
    clearbit.key = 'sk_1915de5d2d7b6e245d6613e3d2188368'
    df = pd.read_csv("/home/vipul/Desktop/new.csv", sep=',', encoding="utf-8")
    saved_column = df['Company'].dropna()
    res = []
    for data in saved_column:   
        n = saved_column[i]
        i = i+1
        data = clearbit.NameToDomain.find(name=n)
        if data is None null() res.append(data['domain'])
    df['domain'] = res
    df.to_csv("/home/vipul/Desktop/new.csv",index = False, skipinitialspace=False)
    print("File saved to desktop as new.csv")

Open in new window

**output of the code**
    python ts.py
    0                ‎Accenture
    1              ‎AND Digital
    2                ‎Accenture
    3    ‎Kite Consulting Group
    4                ‎Capgemini
    5             ‎Accenture UK
    Name: Company, dtype: object
    ['accenture.com', 'and.digital']
    ['accenture.com', 'and.digital', 'accenture.com']
    Traceback (most recent call last):
      File "ts.py", line 15, in <module>
    TypeError: 'NoneType' object is not subscriptable

Open in new window


How to give some default value where NoneType encounters and store it with the corresponding company names which is in new.csv

**Expected output to be saved in new.csv**

    Company                  domain
    ‎Accenture                accenture.com
    ‎AND Digital              and.digital
    ‎Accenture                accenture.com
    ‎Kite Consulting Group    None
    ‎Capgemini                capgemini.com
    ‎Accenture UK             None
Question by:Vipul Rao

Featured Post

Turn Raw Data into a Real Career

There’s a growing demand for qualified analysts who can make sense of Big Data. With an MS in Data Analytics, you can become the data mining, management, mapping, and munging expert that today’s leading corporations desperately need.

Join & Write a Comment

What to do if a split doesn't fit? Or a bunch of invoice lines must be rounded while the sum must match a total? It takes a little, but - when done - it is extremely easy to implement.
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question