米琪卡哇伊
dict = {"Province": ["New South Wales", "Victoria", "British Columbia", "", "New South Wales", "Victoria", "British Columbia", ""], "Country": ["Australia", "Australia", "Canada", "USA", "Australia", "Australia", "Canada", "USA"], "Date": ["1/22/20", "1/22/20", "1/22/20", "1/22/20", "1/23/20", "1/23/20", "1/23/20", "1/23/20"], "infected": [12, 10, 6, 5, 2, 3, 4, 5] }import pandas as pdbrics = pd.DataFrame(dict)print(brics)df = brics.set_index(['Country', 'Province', 'Date']).sort_values(['Country', 'Province', 'Date']) print(df)输出: Province Country Date infected0 New South Wales Australia 1/22/20 121 Victoria Australia 1/22/20 102 British Columbia Canada 1/22/20 63 USA 1/22/20 54 New South Wales Australia 1/23/20 25 Victoria Australia 1/23/20 36 British Columbia Canada 1/23/20 47 USA 1/23/20 5 infectedCountry Province DateAustralia New South Wales 1/22/20 12 1/23/20 2 Victoria 1/22/20 10 1/23/20 3Canada British Columbia 1/22/20 6 1/23/20 4USA 1/22/20 5 1/23/20 5