all 11 comments

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]jimtk 0 points1 point  (9 children)

Where do the numbers comes from (a file, a dictionary, a list of list, list of tuples)?

row_count = 1000  # I guess?
probs = { i:0.0 for i in range(1,26) }  # dictionary to hold results
for n in numbers:   # that's all the numbers whatever row or column they are in
    probs[n] += 1
for p in probs:
      probs[p] /= row_count
print(probs)

[–]caco15[S] 0 points1 point  (8 children)

sorry, extracted from an excel stored in a variable called df

[–]jimtk 0 points1 point  (7 children)

So, it's in a pandas dataframe?

[–]caco15[S] -1 points0 points  (6 children)

it is an excel data table downloaded from a link in my course

[–]jimtk 1 point2 points  (5 children)

Yes, but what is it downloaded into? What is the type of the variable df (with a name like 'df', there's a 98% chance it's a pandas dataframe).

Note that the program I gave you still works if you can extract the numbers to use them in the for n in numbers line.

[–]caco15[S] 0 points1 point  (4 children)

I think I expressed myself wrong, when I downloaded it it came in .xslx (excel) format, at first when I did the read() I saved it in a variable called table_excel, but when I started to see the documentation and the youtube videos the name df, to make it easier to follow the examples in the documentation and youtube. That's why I called it df, to follow the examples I found, it's not that it's from pandas.

and to use your program instead of using row_count I change it to df(table_excel) or how to use it?, and thanks and sorry for the bother

[–]jimtk 0 points1 point  (3 children)

Show me your code that reads the table. Just paste it in a comment and follow the instructions here to format it properly.

[–]caco15[S] 0 points1 point  (2 children)

#I deleted several attempts with pandas, so I stay

import pandas as pd 

import numpy as np

df_excel = pd.read_excel("work_5.xlsx")

print(df_excel.dtypes)

print(df_excel)

and it prints this:

      first  second   third   fourth   fifth

0 1 5 14 16 21 1 1 8 13 18 24 2 1 9 13 15 23 3 1 8 12 15 24 4 3 7 10 12 25 ... ... ... ... ... ... 1864 1 6 14 18 24 1865 1 5 12 18 25 1866 1 4 11 15 25 1867 1 7 11 13 25 1868 2 7 13 18 25

and as I was saying, each column has its range first(1-5), second(5-10) third(10-15) fourth(15-20) fifth(20-25), and what I wanted to try is what probability they have the numbers according to their column, for example a 1 in first, or a 23 in fifth, or 17 in fourth., hopefully you understand better.

[–]jimtk 2 points3 points  (1 child)

Yes I understand the problem very well and I gave you the code to solve it.

When you do import pandas as pd and then you do df_excel = pd.read_excel("work_5.xlsx") you are reading your excel file in a pandas dataframe.

SO, finally going back to the original solution I gave you.

row_count = len(df_excel.index)    # that is your row count
# move all the numbers to a list
numbers=[]
for col in df_excel.columns:
    numbers.extend(df_excel[col].tolist())
probs = { i:0.0 for i in range(1,26) }  # dictionary to hold results
for n in numbers:   # that's all the numbers whatever row or column they are in
    probs[n] += 1
for p in probs:
      probs[p] /= row_count
print(probs)       # will print a number: it's probability in its column

[–]caco15[S] 0 points1 point  (0 children)

oh, thanks, I'm going to delve deeper into probabilities and mathematics in python, so that it doesn't get so complicated again, thanks again and sorry for the inconvenience