Count fequency of a list in range 0-10, and outputing this frequency including 0 - python-3.x

I have a program that will ask the user for a number as many times as they want so long as it is within the range 0-10.
I want to then output the frequency of each input for that range including if the number wasn't entered by the user at all. So by default it would be 0.
Here's an example of what I'm looking for.
Input:
1
5
1
2
5
8
9
5
5
Wanted Output:
0 - 0
1 - 2
2 - 0
3 - 0
4 - 0
5 - 4
6 - 0
7 - 0
8 - 1
9 - 1
10 - 0
So far I have a list that stores the users inputs, and a dictionary with keys going from 0-10, with each having a value of 0. I've found code that gives the frequency of the users input but it's unordered and only for the numbers inputed. I'm not sure what to do next.

Related

In Excel, is there an efficient way to sum overlapping Named Rangess?

In Microsoft Excel, I have a named (2D) range. For simplicity, let's assume it looks like this:
1
2
3
4
5
5
4
3
2
1
This represent a time series growth curve, where N number of these could kick off in any point in time. I'm looking for an efficient way to calculate what the cumulative sum of these at any point in time would be, given that N start at that point in time.
So for example, if one starts at time 0, and one at time 3, and two at time 7:
0
1
2
3
4
5
6
7
8
9
1
0
0
1
0
0
0
2
0
0
Then the cumulative total would be:
0
1
2
3
4
5
6
7
8
9
1
2
3
4
5
5
4
3
2
1
1
2
3
4
5
5
4
2
4
6
---
---
---
---
---
---
---
---
---
---
1
2
3
5
7
8
8
10
11
11
I'd like to write a formula that gets to that total without having to use those extra rows to sum over, but can't figure out how.
Use SUMPRODUCT and INDEX:
=SUMPRODUCT(INDEX($M$1:$V$1,(COLUMN()-COLUMN($A$1:A1)+1)),$A$2:A2)
The ranges are dynamic and increase as it is pulled over.
with versions that are not Office 365 we need to trick INDEX into accepting an array:
=SUMPRODUCT(INDEX($M$1:$V$1,N(IF({1},(COLUMN()-COLUMN($A$1:A1)+1)))),$A$2:A2)
This would then be confirmed with Ctrl-Shift-Enter to make it an array formula.

Pandas DataFrame: how do we keep columns based on the index name?

I seem to run into some python or enumerate bugs that I am not quite sure how to fix it (See here for more details).
Long story short, I desire to see multiple data sets that has a column name of 0,4,6,8,10,12,14.
0 4 6 8 10 12
1 2 5 4 2 1
5 3 0 1 5 10
....
But my current data looks like the following
0 4 2 6 8 10 12
1 2 5 4 2 1
5 3 0 1 5 10
....
Therefore, I would like to add a code that keeps columns based on the index number (including only 0,4,6,8,10,12).
Is there a pandas function that can help with this?

Find a subset of rows (N rows) in a Pandas data frame having the same values at a subset of columns

I have a df which contains customer data without a primary key. The same customer might show up multiple times.
I have a field (df2['campaign']) that is an int and reflects how many times the customer shows up in the df. There are also many customer attributes.
In my example, going from top to bottom, for each row (i.e. customer), I would like to find all n rows (i.e. all n customers) whose values of the education and default columns are the same. Remember n is the int contained in df2['campaign']
So as shown below, for row 0 and 1 I should search 1 row but find nothing because there are no matching values for education-default combinations.
For row 2 I should search 1 row (because campaign == 1) where education-default values match, and find 1 row in index 4.
df2.head()
job marital education default campaign housing loan contact
0 3 1 0 0 1 0 0 1
1 7 1 3 1 1 0 0 1
2 7 1 3 0 1 2 0 1
3 0 1 1 0 1 0 0 1
4 7 1 3 0 1 0 2 1
Use df2_sorted = df2.sort(['education', 'default'], ascending=[1, 1]).
Then if your data is not noisy, the rows should become neighbors.

Function coverage () in R

I want to understand what the function coverage does to an IRange. for example the codes below:
ir <- IRanges (1:3, width = 3)
ir
IRanges object with 3 ranges and 0 metadata columns:
start end width
[1] 1 3 3
[2] 2 4 3
[3] 3 5 3
coverage (ir)
integer-Rle of length 5 with 5 runs
Lengths: 1 1 1 1 1
Values : 1 2 3 2 1
why the values repeats itself like 123 then 21
I figured it out.
The right answer is that we count the ranges covering each number starting from 1 till the last number in the last range.
for example
ir <- IRanges (4:6, width = 3)
first, we draw a plot for that IRange staring from 1 which is not included in any range and ending with 8 which is the boundry of the last range
second, we count the ranges of the Ir that covers each of these number from 0 to 8
count = c (0,0,0,1,2,3,2,1)
Rle (count)
numeric-Rle of length 8 with 6 runs
Lengths: 3 1 1 1 1 1
Values : 0 1 2 3 2 1

In excel, how to use an array formula to sum a range to offsets of itself, generating a new "sum" range?

I'd like to use an array formula to sum a range to multiple offsets of itself: for example, given the following range: {3,4,5,6,7} (say in cells A1:A5), I'd like to get the range added to itself, say 4 times, but each addition is offset by one column. So the answer would be a range equal to {3, 3+4, 3+4+5, 3+4+5+6, 3+4+5+6+7, 4+5+6+7, 5+6+7, 6+7, 7}
Here is an example, offset by rows:
3
4 3
5 4 3
6 5 4 3
7 6 5 4 3
0 7 6 5 4
0 0 7 6 5
0 0 0 7 6
0 0 0 0 7
=
3
7
12
18
25
22
18
13
7
Put the following in your first desired cell:
=IF(ROW(1:1)< COUNT($1:$1)*2,SUM(INDEX($1:$1,IF(ROW(1:1)<COUNT($1:$1),1,ROW(1:1)-COUNT($1:$1)+1)):INDEX($1:$1,MIN(ROW(1:1),COUNT($1:$1)))),"")
Then copy down. As numbers are added or subtracted from the first row the answer will change to match. Just copy down sufficient rows to cover twice the greatest number of values in row 1.

Resources