0

I have a flat file with 31 rows and around 50k columns.

  1. import file and group to new data frame. The code below works and results is shown:

    RTE_subject = rte.groupby(by=["RTE Subject Type", "Account: External ID"]).agg({"Sent":"sum",                                                     "Opened":"sum",                                                                           "Clicked":"sum"})
    RTE_subject["cr"]=RTE_subject.Opened/RTE_subject.Sent
    RTE_subject["ctr"]=RTE_subject.Clicked/RTE_subject.Opened
    print(RTE_subject.head())
    

    results of the code:

    results of the code

  2. I try to build box plot using RTE_subject:

    sns.catplot(data=RTE_subject,
                x="RTE Subject Type",
                y="ctr",
                kind="box")
    plt.show()
    

    but got this message ValueError: Could not interpret input 'RTE Subject Type'.

Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • when you group by that column -- and another column -- those two will go into your index, becoming a MultiIndex. you can either specify `x=RTE_subject.index.get_level_values("RTE Subject Type")` or get that part of the MultiIndex back into the DataFrame's columns. – mechanical_meat Jan 11 '22 at 15:33
  • 2
    possibly `RTE_subject.reset_index()` -- to "flatten" the MultiIndex -- would be a better solution if you're doing anything else to that DataFrame. – mechanical_meat Jan 11 '22 at 15:43
  • 1
    Thank you index reset, has helped! – Maksim .Levin Jan 11 '22 at 15:49

0 Answers0