Questions tagged [frequency]

The rate at which a thing occurs or is found.

The rate at which a thing occurs or is found.

2858 questions
490
votes
16 answers

Count the frequency that a value occurs in a dataframe column

I have a dataset category cat a cat b cat a I'd like to return something like the following which shows the unique values and their frequencies category freq cat a 2 cat b 1
yoshiserry
  • 20,175
  • 35
  • 77
  • 104
285
votes
33 answers

How to count the frequency of the elements in an unordered list?

Given an unordered list of values like a = [5, 1, 2, 2, 4, 3, 1, 2, 3, 1, 1, 5, 2] How can I get the frequency of each value that appears in the list, like so? # `a` has 4 instances of `1`, 4 of `2`, 2 of `3`, 1 of `4,` 2 of `5` b = [4, 4, 2, 1, 2]…
Bruce
  • 33,927
  • 76
  • 174
  • 262
241
votes
10 answers

Relative frequencies / proportions with dplyr

Suppose I want to calculate the proportion of different values within each group. For example, using the mtcars data, how do I calculate the relative frequency of number of gears by am (automatic/manual) in one go with…
jenswirf
  • 7,087
  • 11
  • 45
  • 65
175
votes
2 answers

What values are valid in Pandas 'Freq' tags?

I am trying to use date_range. I came across some values valid for freq, like BME and BMS and I would like to be able to quickly look up the proper strings to get what I want. What values are valid in Pandas 'Freq' tags?
sundowner
  • 1,898
  • 2
  • 13
  • 7
124
votes
7 answers

Getting the count of unique values in a column in bash

I have tab delimited files with several columns. I want to count the frequency of occurrence of the different values in a column for all the files in a folder and sort them in decreasing order of count (highest count first). How would I accomplish…
sfactor
  • 12,592
  • 32
  • 102
  • 152
116
votes
4 answers

How can I compute a histogram (frequency table) for a single Series?

How can I generate a frequency table (or histogram) for a single Series? For example, if I have my_series = pandas.Series([1,2,2,3,3,3]), how can I get a result like {1: 1, 2: 2, 3: 3} - that is, a count of how many times each value appears in the…
Abe
  • 22,738
  • 26
  • 82
  • 111
102
votes
7 answers

python equivalent of R table

I have a list [[12, 6], [12, 0], [0, 6], [12, 0], [12, 0], [6, 0], [12, 6], [0, 6], [12, 0], [0, 6], [0, 6], [12, 0], [0, 6], [6, 0], [6, 0], [12, 0], [6, 0], [12, 0], [12, 0], [0, 6], [0, 6], [12, 6], [6, 0], [6, 0], [12, 6], [12, 0], [12, 0], [0,…
Donbeo
  • 17,067
  • 37
  • 114
  • 188
92
votes
15 answers

Count frequency of words in a list and sort by frequency

I am using Python 3.3 I need to create two lists, one for the unique words and the other for the frequencies of the word. I have to sort the unique word list based on the frequencies list so that the word with the highest frequency is first in the…
user3088605
  • 951
  • 1
  • 8
  • 5
69
votes
14 answers

Item frequency count in Python

Assume I have a list of words, and I want to find the number of times each word appears in that list. An obvious way to do this is: words = "apple banana apple strawberry banana lemon" uniques = set(words.split()) freqs = [(item,…
Daniyar
  • 1,680
  • 2
  • 15
  • 23
57
votes
6 answers

How to get the number of the most frequent value in a column?

I have a data frame and I would like to know how many times a given column has the most frequent value. I try to do it in the following way: items_counts = df['item'].value_counts() max_item = items_counts.max() As a result I get: ValueError:…
Roman
  • 124,451
  • 167
  • 349
  • 456
53
votes
9 answers

How to count how many values per level in a given factor?

I have a data.frame mydf with about 2500 rows. These rows correspond to 69 classes of objects in colum 1 mydf$V1, and I want to count how many rows per object class I have. I can get a factor of these classes with: objectclasses =…
Escher
  • 5,418
  • 12
  • 54
  • 101
51
votes
11 answers

How to find most common elements of a list?

Given the following list ['Jellicle', 'Cats', 'are', 'black', 'and', 'white,', 'Jellicle', 'Cats', 'are', 'rather', 'small;', 'Jellicle', 'Cats', 'are', 'merry', 'and', 'bright,', 'And', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.', …
user434180
  • 735
  • 1
  • 5
  • 9
49
votes
3 answers

Getting frequency values from histogram in R

I know how to draw histograms or other frequency/percentage related tables. But now I want to know, how can I get those frequency values in a table to use after the fact. I have a massive dataset, now I draw a histogram with a set binwidth. I want…
MiMi
  • 548
  • 1
  • 5
  • 8
46
votes
6 answers

Python library for playing fixed-frequency sound

I have a mosquito problem in my house. This wouldn't usually concern a programmers' community; However, I've seen some devices that claim to deter these nasty creatures by playing a 17Khz tone. I would like to do this using my laptop. One method…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
44
votes
1 answer

How to use dplyr to generate a frequency table

I like to create a table that has the frequency of several columns in my data frame. I am copying part of my data frame below. The table is supposed to have frequency (both n and %) of "red" in Color and "F" in Gender. I think that the dplyr…
Rooz
  • 479
  • 1
  • 4
  • 6
1
2 3
99 100