in Education by
I have several csv columns that store lottery numbers and some other info, like date when the number was drawn. I need to get a dictionary as my output. So far I have been able to print number of occurrences in each column individually. # Import libraries import pandas as pd from IPython.display import display # Turn csv file into a pandas dataframe df = pd.read_csv("LOTTOMAX.csv") # Only select columns that I'm interested in. Csv file contains additional useless info. selection = df[['NUMBER DRAWN 1', 'NUMBER DRAWN 2', 'NUMBER DRAWN 3', 'NUMBER DRAWN 4', 'NUMBER DRAWN 5', 'NUMBER DRAWN 6', 'NUMBER DRAWN 7']] # Loop over columns and apply value_counts(). Output to terminal. for col in selection.columns: # I have included this to make terminal output more readable. print('-' * 40 + col + '-' * 40 , end='\n') display(selection[col].value_counts().to_string()) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I did this project for fun. Wanted to replicate a feauture on bclc website. Perhaps this will help someone. # Import libraries import pandas as pd from collections import Counter import matplotlib.pyplot as plt # Read csv file df = pd.read_csv("LOTTOMAX.csv") #csv file https://www.playnow.com/resources/documents/downloadable-numbers/LOTTOMAX.zip cols = ['NUMBER DRAWN 1', 'NUMBER DRAWN 2', 'NUMBER DRAWN 3', 'NUMBER DRAWN 4', 'NUMBER DRAWN 5', 'NUMBER DRAWN 6', 'NUMBER DRAWN 7'] results = [] # Add data to a list for i in cols: results += df[i].tolist() # Count occurrences occurr = Counter(results) # Display histogram plt.bar(list(occurr.keys()), occurr.values(), color='g') plt.xlabel("Numbers Drawn") plt.ylabel("Frequency") plt.show() This solution is imperfect, but it works.

Related questions

0 votes
    I have a dataset |category| cat a cat b cat a I'd like to be able to return something like (showing unique values ... cat a 2 cat b 1 Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I have an item and I want to count it's occurrence in a list, How can I do that in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have data like this: id a b c d 1 y y z z 2 y z y y 3 y y y y I want to count the value of "y" ... 1 2 2 1 3 4 Can anyone help me? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I have the function and want to create a new column df['growth_factor'] which will have a derived value in it. ... can I achieve this? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have the dataset that has the no_employees column that is the str object. whats is a best way to create the new ... 1-5 |Very Small Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Jupyter notebooks (Python) return the value of the last variable in a cell in a pretty printed format. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    float('nan') results Nan (not a number). It is very easy but how can I check? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I need to get a line count of a large file (hundreds of thousands of lines) in python. What is the most ... possible to do any better? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I have the data frame that looks like this: Date Visa Mastercard Amex Paypal 1/1/20 0 20 0 0 2/1/20 ... info() Any help is appreciated Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    How can I remove emojis that start with '\x' when reading a csv file using pandas in Python? The ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    My data looks as follows: ID my_val db_val a X X a X X a Y X b X Y b Y Y b ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    What's the simplest way to count the number of occurrences of a character in a string? e.g. count the number of ... had a little lamb' Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    What exactly is the difference between groupby("x").count and groupby("x").size in Pandas? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I want to calculate a percentage, for each id, of True values from all rows of the id. Here an example ... df.num_true/df.num_col1_id Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have some long data I need to convert into a wide fixed width text format. I have a large ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
...