0

I am trying to return all correct data when a condition is met. I would like to return all the relevant records when there has been X amount of goals scored by the home team.

data = pd.read_csv("epl_data_v2.csv")

def highest_home_score():
    data.loc[data['HG']==1]

The console is returning the value None. I'm not sure why this happens. I know the column name 'HG' is correct.

Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    That code does nothing to the df. You don't call your function. If you _did_, it would return `None` because the function doesn't have a `return`. It's not at all clear what you're trying to do, please give a [mcve] – roganjosh Jan 03 '20 at 00:51
  • Your function doesn't return anything, so it implicitly returns `None`, what were you *expecting*? – juanpa.arrivillaga Jan 03 '20 at 00:53

1 Answers1

-1
def highest_home_score():
    print(data.loc[data['HG']==1])

highest_home_score()

The code above produces what I was expecting - a small set of results that feature 1 as the HG value.

  • 1
    This is really not good code. You're calling a function just to `print` something from the df? As a self-answered question, it doesn't even match the question because you never showed the function call – roganjosh Jan 03 '20 at 00:59
  • How would you suggest? I'm extremely new to programming so am unsure as to why this would be bad – DavidBobo Jan 03 '20 at 01:00
  • I would suggest dropping the function entirely. `print(data[data['HG'] == 1])` and in-line it. This `print` will be of little use beyond debugging if you have any reasonable number of records in the dataframe – roganjosh Jan 03 '20 at 01:03