Python Forum
value_counts method question
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
value_counts method question
#4
(Mar-22-2017, 10:15 PM)zivoni Wrote: Pandas has no problems to count values in boolean columns, but there are some problems with your code:

When you convert your list to a dataframe, you are not supplying a column name, neither you rename the column later - so your dataframe has only one column 0 (numerical index). When you try to select test2['sum1'], it raises an error - there are only integers in range index (it probably raises KeyError somewhere too). You can access your column with test2[0] or with ix/iloc/loc, but better would be to rename it or provide column name when you create the dataframe (either columns parameter or pd.DataFrame({'sum1': test}) ).

And you are appending to test only in else clause, so your list will consist only of "False"s (misindented line?).

Thank you so much for the help. I forgot I needed to supply the DataFrames argument with a columns parameter if I wanted to reference it as "sum1." Additionally, I did forget to add an append method in my if clause as well. Thanks for noticing that.
Reply


Messages In This Thread
value_counts method question - by smw10c - Mar-22-2017, 07:23 PM
RE: value_counts method question - by nilamo - Mar-22-2017, 07:51 PM
RE: value_counts method question - by zivoni - Mar-22-2017, 10:15 PM
RE: value_counts method question - by smw10c - Mar-22-2017, 10:36 PM
RE: value_counts method question - by zivoni - Mar-22-2017, 10:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pd.query method question PolskaYBZ 5 3,169 Jan-25-2019, 08:23 PM
Last Post: stullis
  PyCharm IDE: Method Not Showing Up Question: Bug or Feature? Oliver 2 3,786 Dec-04-2017, 11:54 AM
Last Post: Oliver
  Apply Method Question smw10c 4 5,616 Apr-08-2017, 12:47 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020