python sequence item 0_如何修复“TypeError:sequence item 0:预期str实例,找到float”

我尝试使用groupby方法组合dataframe列中的单元格值(字符串),使用逗号分隔分组单元格中的单元格值。我遇到了以下错误:TypeError: sequence item 0: expected str instance, float found

错误发生在以下代码行,有关完整代码,请参阅代码块:

^{pr2}$

在groupby函数中,与未分组的dataframe中的每一行相对应的索引在联接之前自动添加到字符串中。这会导致类型错误。但是,我不知道如何解决这个问题。我浏览了很多帖子,但没有找到解决办法。如果有任何指导或帮助,我将不胜感激!在# Import Necessary Libraries

import numpy as np

import pandas as pd

from bs4 import BeautifulSoup

import requests

# Use BeautifulSoup to scrap information in the table from the Wikipedia page, and set up the dataframe containing all the information in the table

wiki_html = requests.get('https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M').text

soup = BeautifulSoup(wiki_html, 'lxml')

# print(soup.prettify())

table = soup.find('table', class_='wikitable sortable')

tabl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值