基于列值创建列表

2024-03-29 12:36:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的df,我正试图根据“combined\ u sector”列中的值创建一个逗号分隔的列表。结果应如下所示:

IG信贷:金融-雷曼部门:“46647PAY2”、“36164QMS4”、“36164QMS4”

高收益:工业-雷曼行业:“26112TAJ5”,“29273VAD2”

    cusip   sector_path_0   sector_path_1   sector_path_2   combined_sector
0   46647PAY2   FMBI UNIV Breakdown IG Credit   Financials - Lehman Sector  IG Credit: Financials - Lehman Sector
1   36164QMS4   FMBI UNIV Breakdown IG Credit   Financials - Lehman Sector  IG Credit: Financials - Lehman Sector
2   948741AH6   FMBI UNIV Breakdown IG Credit   Financials - Lehman Sector  IG Credit: Financials - Lehman Sector
3   26112TAJ5   FMBI UNIV Breakdown High Yield  Industrials - Lehman Sector High Yield: Industrials - Lehman Sector
4   29273VAD2   FMBI UNIV Breakdown High Yield  Industrials - Lehman Sector High Yield: Industrials - Lehman Sector

是否可以选择在哪些列上使用df['column'].values.tolist()?也就是说,我可以选择从哪些列创建列表吗?你知道吗


Tags: pathdfunivcredityieldhighsectorcombined