Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Counting Criteria in Pandas Question
#1
Hello,
Not sure where I'm going wrong at. Any help would be appreciated.

I have a csv file that has win/loss/draw data. Quick brief of the csv file:
3 comma separated columns. Columns are "Side", "Result" and "Year" with data below.

I'm trying to get the data from the csv file to pandas in python and to count the number of times "Win" appears but I'm getting a Key Error: 'Win' when I run the below script. Confirmed "Win" is in the csv file.


from pandas import DataFrame, read_csv
import matplotlib.pyplot as plt
import pandas as pd 

df = pd.read_csv('test.csv')
df[df["Result"]==1].count()["Win"]
print(df)
Quote
#2
Is there any particular reason to import ths way:

from pandas import DataFrame, read_csv
import pandas as pd
You could use .value_conts() for counting values:

>>> df = pd.DataFrame({'numbers': range(1, 6), 'letters': [*'abaca']})
>>> df
   numbers letters
0        1       a
1        2       b
2        3       a
3        4       c
4        5       a
>>> df.letters.value_counts()['a']
3
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Life of Brian: Conjugate the verb, "to go" !
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Function question using Pandas smw10c 7 2,687 Feb-12-2019, 06:52 PM
Last Post: Nathandsn
  Simple pandas dataframe question popohoma 1 567 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  question on pandas datareader kit12_31 3 4,088 Feb-05-2018, 11:55 PM
Last Post: snippsat
  Newbie question on how to use pandas.rolling_mean zydjohn 5 7,676 Dec-09-2017, 08:42 PM
Last Post: j.crater
  Pandas question takaa 3 1,251 Dec-05-2017, 01:03 PM
Last Post: takaa
  Select rows based on a criteria klllmmm 8 2,874 May-11-2017, 06:58 PM
Last Post: klllmmm
  Pandas merge question smw10c 1 2,151 May-05-2017, 09:57 PM
Last Post: zivoni
  drop duplicate values based on a criteria klllmmm 1 2,196 Apr-28-2017, 10:17 AM
Last Post: zivoni
  Insert values into a column in the same table based on a criteria klllmmm 3 1,671 Apr-13-2017, 10:10 AM
Last Post: zivoni

Forum Jump:


Users browsing this thread: 1 Guest(s)