Reputation: 368
I have my list which is stored in info
and it contains -
['Stephanie Ramirez', 'Greater Tampa Bay Area', '500+ connections', 'Jacobs', 'Technical Recruiter', '2019 – Present', '2 yrs']
how i wanted it to be in a dataframe so that I can export it to an excel file later like -
name | location | connection | company | position | duration | tenure |
---|---|---|---|---|---|---|
Stephanie Ramirez | Greater Tampa Bay Area | 500+ connections | Jacobs | Technical Recruiter | 2019 – Present | 2 yrs |
here's my code where it extracts data and appends in info
name_div = soup.find('div', {'class': 'flex-1 mr5'})
name_loc = name_div.find_all('ul')
name = name_loc[0].find('li').get_text().strip()
loc = name_loc[1].find('li').get_text().strip()
connection = name_loc[1].find_all('li')
connection = connection[1].get_text().strip()
info = []
info.append(name)
info.append(loc)
info.append(connection)
info
['Stephanie Ramirez', 'Greater Tampa Bay Area', '500+ connections']
#experience setion
exp_section = soup.find('section', {'id': 'experience-section'})
exp_section = exp_section.find('ul')
div_tag = exp_section.find('div')
a_tag = div_tag.find('a')
job_title = a_tag.find('h3').get_text().strip()
company_name = a_tag.find_all('p')[1].get_text().strip()
joining_date = a_tag.find_all('h4')[0].find_all('span')[1].get_text().strip()
exp = a_tag.find_all('h4')[1].find_all('span')[1].get_text().strip()
info.append(company_name)
info.append(job_title)
info.append(joining_date)
info.append(exp)
info
['Stephanie Ramirez', 'Greater Tampa Bay Area', '500+ connections', 'Jacobs', 'Technical Recruiter', '2019 – Present', '2 yrs']
please help me to get my desired OP in a dataframe. Thanks in advance!!
just asking, the way I have posted the question is it the right way?
Upvotes: 2
Views: 37
Reputation: 34086
Use df.T
:
In [131]: import pandas as pd
In [132]: info = ['Stephanie Ramirez', 'Greater Tampa Bay Area', '500+ connections', 'Jacobs', 'Technical Recruiter', '2019 – Present', '2 yrs']
In [137]: df = pd.DataFrame(info).T
In [139]: df.columns = ['name', 'location', 'connection', 'company', 'position', 'duration', 'tenure']
In [140]: df
Out[140]:
name location connection company position duration tenure
0 Stephanie Ramirez Greater Tampa Bay Area 500+ connections Jacobs Technical Recruiter 2019 – Present 2 yrs
Upvotes: 1