0

I'm very new to python.

How do I get a string like this:

53 (46.49 %)

But, I'm getting this:

1    53 (1    46.49 %)

I'm trying to get the last value from the table count and the proportion (i'm not sure what it's called in python)

table = pd.value_counts(data[var].values, sort=False)
prop_table = (table/table.sum() * 100).round(2)

num = table[[1]].to_string()
prop = prop_table[[1]].to_string()

test = num + " (" + prop + " %)"

but, it puts 1 before displaying the number.

blhsing
  • 91,368
  • 6
  • 71
  • 106
user1828605
  • 1,723
  • 1
  • 24
  • 63
  • 1
    Can we have a reproducible example of the DataFrame `data`? – Ekaba Bisong Jul 19 '18 at 04:27
  • 3
    Possible duplicate of [How to print dataframe without index](https://stackoverflow.com/questions/24644656/how-to-print-dataframe-without-index). Try `table[[1]].to_string(index=False)` – Zev Jul 19 '18 at 04:27
  • 1
    or just remove the extra `[]` so `num = table[1].to_string()` – gyx-hh Jul 19 '18 at 10:35
  • @Zev, Thank you. That was it. I use R most of the times, but I'm making an effort to learn and use Python more. – user1828605 Jul 19 '18 at 12:52

0 Answers0