Sampling from a frequency distribution I have a dataset representing a frequency distribution:
|item|frequency|
|-|-|
|a|1|
|b|1|
|c|1|
|d|1|
|e|2|
|f|2|
|g|10|
h,143
j,724
The data is fairly exponential in character, with a few items occurring frequently, then a long tail of single occurrences.  The dataset is >>1 million lines/items is size.  What is the best way to take a random sample from the distribution?  This would be python code not R.

Python offers many options for sampling from a set with specified frequencies. To give a few widely sued ones:
Native python
Python offers many sueful functions in its random module, specifically

*

*random.sample() - for sampling without replacement

*random.choices() for sampling with replacement

Numpy
Numpy has its own random module with somewhat different syntax:

*

*numpy.random.choice() performs sampling with and without replacement, and weith specified probabilities (which may be somewhat inconvenient for the count data, rather than directly sampling from a set, but probably does the same thing).

Pandas
Pandas is a good choice in terms of importinga nd manipulating data, and offers its own sampling function (likely with a numpy backend):

*

*pandas.DataFrame.sample
