我尝试在一个数据帧中组合两个具有相同邮政编码的邻居名称
最初我使用groupby.unique()
函数,但它在每个单元格中返回一个ndarray
。后来我尝试了groupby.first()
函数,它返回重复的邮政编码的值
PCode =pd.DataFrame({'PostalCode':['M4A','M5A','M5A'],'Borough':['North York','Downtown Toronto','Downtown Toronto'],'Neighbourhood':['Victoria Village','Harbourfront','Regent Park']})
PCode.groupby('PostalCode')['PostalCode'].unique()
PCode.groupby('PostalCode')['PostalCode'].first()
我想知道是否有办法从返回的ndarray
中提取邮政编码,以便groupby.unique()
函数产生与使用groupby.first()
函数时完全相同的结果
使用
str[0]
:相关问题 更多 >
编程相关推荐