I have generated a DF from the below code:
url='https://www.rootsandrain.com/event4493/2017-aug-26-uci-world-cup-dh-7-val-di-sole/results/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
table = soup.find('table', {'class':'list'})
headers = [heading.text for heading in table.find_all('th')]
response = requests.get(url)
dfs = pd.read_html(response.text)[0]
#rename headers
dfs.rename(columns = {'Pos⇧' : 'Race_Pos'}, inplace = True)
df_sf = dfs.iloc[:,[1,3,5,14]].copy()
#df_sf['Race_rank'] = df_sf['Race_Pos'].rank()
#df_sf['Race_Pos'] = df_sf['Race_Pos'].astype('str')
#df_sf['Race_Pos_Num'] = df_sf['Race_Pos'].str[:-2]
df_sf['Race_Pos']=df_sf.index
print(df_sf)
print(df_sf.dtypes)
Then also extracted the title (as yet uncleaned) using this code:
print(soup.h1)
However I want to add this value to each row of the table. I can add a fixed value such as assign a new column with a value of 'X' but when I try to assign the title to the X value I get an error.
How to do this?