0

I have the below df that I am trying to create a comma delimeted list from based on the values in the "combined_sector" column. The result should look like the following:

IG Credit: Financials - Lehman Sector: '46647PAY2', '36164QMS4','36164QMS4'

High Yield: Industrials - Lehman Sector: '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

Is it possible to select which columns to use df['column'].values.tolist() on? Meaning, can i select which columns to create a list from?

benvc
  • 14,448
  • 4
  • 33
  • 54
J.M.
  • 1
  • 1
  • Possible duplicate: https://stackoverflow.com/questions/22341271/get-list-from-pandas-dataframe-column – Rick M. Feb 20 '19 at 16:30
  • 1
    `df[['col1','col2']].values.tolist()` – mad_ Feb 20 '19 at 16:32
  • Thanks - the issue I am seeing is that I want to essentially "pivot" the data to just get the list of values from the "dependent" column (cusip in the above df) into a single string based on the "independent" column (combined_sector). Is this possible? – J.M. Feb 20 '19 at 16:46

0 Answers0