Duplicate rows in dataframe and add

Viewed 45

I will organize people's work information in a table. I'm getting people info from the web and adding them to a list. There are 2 unique numbers that characterize these contacts. The loop goes to the 2nd person after getting the university name, study year and title of the 1st person, but I need to add these unique numbers to the table according to this rule.

for i in range(1,3):
 driver.find_element(By.XPATH,"/html/body/div/div[2]/div[2]/div[2]/table/tbody/tr[{}]/td[3]/h4/a".format(str(i))).click()
 driver.find_element(By.LINK_TEXT,'Kişisel Bilgiler').click()
 a_ID+=([i.text.split()[3].strip("['']") for i in driver.find_elements(By.XPATH,"/html/body/div/div[2]/div[2]/div[1]/div[3]/span")])
 o_ID+=([str(re.findall(r'(\d+-+\d+-+\d+-+\d+)',i.text)).strip("['']") for i in driver.find_elements(By.XPATH,".//span[@class='pull-right greenOrcid']/p")])
 year+=([i.text for i in driver.find_elements(By.CSS_SELECTOR,"div.col-lg-10.col-md-10.col-sm-12.col-xs-12 > div.container-fluid > div > div:nth-child(1) > div > div >ul>li:nth-child(2n)>span")])
 title+=([i.text for i in driver.find_elements(By.CSS_SELECTOR,"div.col-lg-10.col-md-10.col-sm-12.col-xs-12 > div.container-fluid > div > div:nth-child(1) > div > div >ul>li:nth-child(2n+1)>div.timeline-footer > a")])
 uni+=([i.text for i in driver.find_elements(By.CSS_SELECTOR,"div.col-lg-10.col-md-10.col-sm-12.col-xs-12 > div.container-fluid > div > div:nth-child(1) > div > div >ul>li:nth-child(2n+3)>div.timeline-item>h4")])
 driver.back()
    k=[]
    k.extend([a_ID,o_ID,uni,year,title])
    m=pd.DataFrame(k)
    c=m.T

This is output of the dataframe c.

This is the dataframe I want it to be. enter image description here

How can I distribute these IDs?

1 Answers

Probably you can assign the values in ID columns in the end of your for loop & update something like this;

a_ID = a_ID + ID value * len(year)

where ID value is the extracted original ID, & getting multiplied by the total length of either uni or year or title.

Hope it Helps...

Related