Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Counting Criteria in Pandas Question
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')
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']
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

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Function question using Pandas smw10c 7 3,224 Feb-12-2019, 06:52 PM
Last Post: Nathandsn
  Simple pandas dataframe question popohoma 1 798 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  question on pandas datareader kit12_31 3 5,167 Feb-05-2018, 11:55 PM
Last Post: snippsat
  Newbie question on how to use pandas.rolling_mean zydjohn 5 9,082 Dec-09-2017, 08:42 PM
Last Post: j.crater
  Pandas question takaa 3 1,627 Dec-05-2017, 01:03 PM
Last Post: takaa
  Select rows based on a criteria klllmmm 8 3,435 May-11-2017, 06:58 PM
Last Post: klllmmm
  Pandas merge question smw10c 1 2,662 May-05-2017, 09:57 PM
Last Post: zivoni
  drop duplicate values based on a criteria klllmmm 1 2,968 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,982 Apr-13-2017, 10:10 AM
Last Post: zivoni

Forum Jump:

Users browsing this thread: 1 Guest(s)