メインコンテンツへスキップ

Convert the headings of a matrix into a list and sort them according to one row

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Marc,

    This is not really a Gurobi question. You should be able to get this done using sort_values. You can specify the axis to sort column-wise instead of along the index and you can slice a DataFrame using loc[mean].

    df = pd.DataFrame()
    df['Product1'] = [253, 29.03, 25]
    df['Product2'] = [158, 15.54, 18.28]
    df['Product3'] = [459, 37.57, 23.01]
    df.index = ['freq','mean','std']
    df.sort_values(by='mean', axis=1).columns

    returns:

    Index(['Product2', 'Product1', 'Product3'], dtype='object')

    Cheers,
    Matthias

    0
  • Marc Schmidt
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you Matthias! The links are very helpful.

    Have a nice weekend !

    0

投稿コメントは受け付けていません。