【发布时间】:2019-10-10 18:08:12
【问题描述】:
如何将不同 for 循环的输出添加到一个数据帧中。例如,我从网站上抓取了数据,并使用循环列出了姓名、电子邮件和电话号码。我想将所有输出添加到单个数据框中的表中。 我可以为一个循环做到这一点,但不能为多个循环做到这一点。 请查看附件中的代码和输出。
从 for 循环中删除 Zip 会导致错误。 “要解压的值太多”
- 循环
phone = soup.find_all(class_ = "directory_item_phone directory_item_info_item")
for phn in phone:
print(phn.text.strip())
##Output - List of Numbers
- df 代码
df = list()
for name,mail,phn in zip(faculty_name,email,phone):
df.append(name.text.strip())
df.append(mail.text.strip())
df.append(phn.text.strip())
df = pd.DataFrame(df)
df
【问题讨论】:
-
邮政编码作为问题的一部分作为文本。没有链接。
-
请将代码以文本形式而非图片形式发布。
标签: python python-3.x pandas for-loop beautifulsoup