I have a pandas dataframe with one of the columns called artist. I would like to append a new row only if the new artist name is not in this column.
I tried but with no success:
if (all_data != name.all(axis = 0)):
all_data = all_data.append({'artist':str(name), 'netWorth':str(worth.strip())}, ignore_index = True)
This is all the code I have:
def get_webpage(i, url):
URL = url+str(i)
response = requests.get(URL)
return bs4.BeautifulSoup(response.text, 'html.parser')
COLUMNS = ['artist', 'netWorth']
all_data = pd.DataFrame(columns = COLUMNS)
def scrape(soup):
artists = soup.find_all('article', class_ = 'thumb-wrap')
for ar in artists:
name = ar.h3.a.text
worth = ar.div.find('div', class_='bc-networth').text
global all_data
if (all_data['artist'] != name).any():
all_data = all_data.append({'artist':str(name), 'netWorth':str(worth.strip())}, ignore_index = True)
i = 1
url = 'http://www.therichest.com/celebnetworth-category/celeb/singer/page/'
while (i<=14):
soup = get_webpage(i, url)
i = i+1
data = scrape(soup)
i = 1
url = 'http://www.therichest.com/celebnetworth-category/celeb/musician/page/'
while (i<=7):
soup = get_webpage(i, url)
i = i+1
data = scrape(soup)