Posts: 29 Threads: 12 Joined: Dec 2018 Hi, I want to know how many times an item appears in a list. If I have a list [1, 2, 2, 2] how would I check if 2 occurs 3 times. Thanks for any help David Posts: 4,216 Threads: 97 Joined: Sep 2016 Posts: 29 Threads: 12 Joined: Dec 2018 Dec-19-2018, 09:12 PM (This post was last modified: Dec-19-2018, 09:18 PM by buran.) Hi, thanks for this tried: if list_name.count(2) = 3 Which gives invalid syntax on the "=" Any ideas? Thanks David Posts: 8,198 Threads: 162 Joined: Sep 2016 Dec-19-2018, 09:18 PM (This post was last modified: Dec-19-2018, 09:19 PM by buran.) = is assignment, == is comparison. you need the latter by the way - with closing tags, use forward slash, not back-slash Posts: 29 Threads: 12 Joined: Dec 2018 Dec-20-2018, 06:34 AM (This post was last modified: Dec-20-2018, 06:35 AM by davidm.) Thanks Buran, works now! You say about Using forward not back slash. I have a more serious problem I'm located in Israel and the text is all right aligned how do I change this to English left aligned Thanks David Posts: 8,198 Threads: 162 Joined: Sep 2016 As explained by @ stranac in your other thread that is browser specific setting For example for Firefox look at https://support.mozilla.org/bg/questions/1128107 Posts: 29 Threads: 12 Joined: Dec 2018 My browser - Chrome - is English ltr only in this forum the post text is rtl when i enter it, after posting it's ltr - very confusing. Posts: 29 Threads: 12 Joined: Dec 2018 Dec-29-2018, 12:00 PM (This post was last modified: Dec-29-2018, 12:50 PM by davidm.) Hi, I'm still trying to get value_counts from multiple columns of a csv file this code: import pandas as pd df = pd.read_csv("lotto-0807-1218.csv") print(df['Num 1'].value_counts().to_frame())Prints the correct value counts for a single column, but how would I get value counts over multiple columns, if I try print(df['Num 1', 'Num 2'].value_counts().to_frame()) I get: Error: KeyError: ('Num 1', 'Num 2')
I want the total for multiple columns not per column Any help much appreciated. Thanks David
Here's the sample lotto-0807-1218.csv Num 1,Num 2,Num 3,Num 4,Num 5,Num 6 15,21,23,27,36,37 8,11,13,18,25,31 1,3,7,9,15,22 7,8,25,31,32,35 3,5,8,18,19,29 2,12,14,18,22,25 3,5,16,18,21,26 6,16,23,24,30,33 9,20,25,27,34,37 16,18,20,22,24,25 8,9,13,14,27,29 2,7,9,19,24,25 4,8,13,20,27,29 6,7,11,17,22,29 11,17,19,25,27,28 Posts: 29 Threads: 12 Joined: Dec 2018 After Googling around since my last post I finally came up with this solution: import pandas as pd df = pd.read_csv("Lottery-numbers-only.csv") print(pd.value_counts(df.values.flatten())) |