How to plot two lists in descending order based on y values?

前端 未结 3 509
甜味超标
甜味超标 2021-01-21 10:12

I have two lists. The first is a list of strings a

[\'Agriculture/Forestry/Fisheries/Veterinary Medicine\',
 \'Architectural and Town Planning\',
 \         


        
3条回答
  •  执笔经年
    2021-01-21 10:36

    Is this what you are trying to do:

    import matplotlib.pyplot as plt
    import pandas as pd
    %matplotlib inline
    
    categories = ['Agriculture/Forestry/Fisheries/Veterinary Medicine',
     'Architectural and Town Planning',
     'Business Administration and Related']
    
    values = [66667.0,22283.0,670091.5]
    
    df = pd.DataFrame(columns=['category', 'value'])
    df = df.append([{"category":a, "value":b} for a, b in zip(categories, values)])
    
    df.sort_values('value', ascending=False)[['category','value']].plot.bar()
    

提交回复
热议问题