我尝试使用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