Whenever I post the following code the output is a group of lists, but how do I organize them into just one column?
# Import libraries
from bs4 import BeautifulSoup
import requests
import pandas as pd
import numpy as np
#Get URL and extract content
class Scraper():
page=1
traits = []
while page != 10:
content = requests.get('https://raw.githubusercontent.com/recklesslabs/wickedcraniums/main/{}'.format(page))
soup = BeautifulSoup(content.text, 'html.parser')
page = page + 1
dic_list = list(map(eval, soup))
for dic in dic_list:
traits = dic["attributes"]
df = pd.DataFrame.from_dict(traits, orient='columns').to_numpy()
df1 = list(np.concatenate(df[0:1]))
print(df1)
When I use the code above I get this output:
['Background', 'Zeus']
['Background', 'BlueWhale']
['Background', 'ViolentViolet']
['Background', 'MardiGras']
['Background', 'WoodBark']
['Background', 'ViolentViolet']
['Background', 'MidnightExpress']
['Background', 'Maire']
['Background', 'Pohutukawa']
How do I make just one column that lists all backgrounds so it can look something like this:
Background
0 Zeus
1 BlueWhale
2 ViolentViolet
3 MardiGras
4 WoodBark
5 ViolentViolet
6 MidnightExpress
7 Maire
8 Pohutukawa
In addition to the above, how would I also go about finding the count for each item so that it shows up as:
Background
Zeus - 1
BlueWhale - 1
ViolentViolet - 2
MardiGras - 1
WoodBark - 1
MidnightExpress - 1
Maire - 1
Pohutukawa - 1