这是我的数据集的一个例子
d={'Report id': [0, 0, 1, 1], 'sentences': ['There is also a faint ground glass nodule. ', 'Other two ill defined, small ground glass lesions are seen.', 'There is a small nodule at medial aspect of left breast, measured 11 mm in size.', 'Two heterogeneous enhancing lesions at lateral segment of left lobe']}
df1 = pd.DataFrame(data=d)
我想根据从0开始的报表id连接数据帧的行。如果行具有相同的报表id,则应将其连接到一行中。下面是我的预期输出
dd = {'Report id': [0, 1], 'sentences': ['There is also a faint ground glass nodule. ' 'Other two ill defined, small ground glass lesions are seen.', 'There is a small nodule at medial aspect of left breast, measured 11 mm in size.' 'Two heterogeneous enhancing lesions at lateral segment of left lobe']}
df2 = pd.DataFrame(data=dd)
我试着像这样连接。请帮帮我
res = pd.concat(df["sentences"], on=['Report id'])
将
groupby
与apply
一起使用例如:
输出:
相关问题 更多 >
编程相关推荐