2 回答
TA贡献1816条经验 获得超4个赞
您可以pd.concat与axis=1参数一起使用:
import pandas as pd
from bs4 import BeautifulSoup
import csv
import requests
line1=[]
url='https://clinicaltrials.gov/ct2/show/NCT03548207'
r=requests.get(url)
soup=BeautifulSoup(r.content,'html.parser')
content=soup.find_all('div',id='main-content')
for item in content:
title=item.find('h1',class_='tr-h1 ct-sans-serif tr-solo_record').text
sponsor=item.find('div', class_='tr-info-text').text
summary=item.find('div',class_='ct-body3 tr-indent2').text
dict={'Title':title,'Sponsor':sponsor,'Summary':summary}
line1.append(dict)
df=pd.DataFrame(line1)
url2='https://clinicaltrials.gov/ct2/show/NCT03548207'
table1=pd.read_html(url2)[2]
dj=pd.DataFrame(table1)
kk = pd.concat([df, dj], axis=1) # <--- pd.concat
print(kk)
kk.to_csv('data.csv', index=False)
印刷:
Title ... Phase
0 A Study of JNJ-68284528, a Chimeric Antigen Re... ... Phase 1 Phase 2
[1 rows x 6 columns]
并保存data.csv(来自 LibreOffice 的屏幕截图):
TA贡献1806条经验 获得超8个赞
转变能解决你的问题吗?
import pandas as pd
df = pd.DataFrame({"a":[0,1,2,3,4,5], 'b':[10, None, 12, 13, 14, 15], 'c':[20, None, 22, 23, 24, 25]})
df.loc[1:,'b':'c']=df.loc[1:,'b':'c'].shift(-1)
print(df)
添加回答
举报