0

i have two dataframes that i merged together and linked each of them to a key

df = pd.concat([dfB, dfC], axis=1, keys=('Gaming','Casual'))
print (df)
             Gaming                                                 Casual      
          brand          price                                  brand      price
cheap   [ASUS,msi]   {'gte': 1047.3, 'lte': 2093.59}        [HP,dell]    {'gte': 1047.3, 'lte': 2093.59}


My Problem is that ,i find it difficult to access my data ,I mean for example how do I get to asus or hp

  • `df.loc['cheap', ('Gaming', 'brand')]` for ASUS, `df.xs('brand', level=1, axis=1)` or `df.loc['cheap'].xs('brand', level=1)` for all brand columns/items – mozway Jul 07 '22 at 13:06
  • Can you help me more, because I ran these instructions but it doesn't work in my program – mohamad jumaa Jul 13 '22 at 19:09
  • Then provide a reproducible input, the incorrect output and the desired output, explaining how it differs. – mozway Jul 13 '22 at 19:18
  • [link] (https://drive.google.com/file/d/1GI57P8NzVKBnE1v9igtKGAk6KpSdsF-6/view?usp=sharing) In this link I uploaded the csv file that I have on Google Drive, can you take a look at it and try to apply it to your device please. I have a project and I have to deliver it soon and I really want help – mohamad jumaa Jul 13 '22 at 19:36
  • Please provide a **minimal** example that reproduces your error, and the matching output – mozway Jul 13 '22 at 19:49
  • KeyError: 'cheap' for df.loc['cheap', ('Gaming', 'brand')] and df.loc['cheap'].xs('brand', level=1) TypeError: Index must be a MultiIndex for df.xs('brand', level=1, axis=1) – mohamad jumaa Jul 13 '22 at 20:20

0 Answers0