I have the following table.

```
Fights (fight_year, fight_round, winner, fid, city, league)

```

I am trying to query the following:

For each year that appears in the Fights table, find the city that held the most fights. For example, if in year 1992, Jersey held more fights than any other city did, you should print out (1992, Jersey)

Here's what I have so far but I keep getting the following error. I am not sure how I should construct my group by functions.

ERROR: column, 'ans.fight\_round' must appear in the GROUP BY clause or be used in an aggregate function. Line 3 from (select \*

```
select fight_year, city, max(*)
from (select *
    from (select *
        from fights as ans
        group by (fight_year)) as l2
     group by (ans.city)) as l1;

```
['https://Stackoverflow.com/questions/64324695', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9905254/']
* If the `pandas.Series` have been converted to a `datetime` format, they will not contain `None`, they will contain `NaT`, which leads me to think, the `Series` are not formatted as `datetime` objects.
* Given a `pandas.DataFrame` with two columns of dates
* Convert the columns to a datetime, with `pandas.to_datetime`
* `.fillna` on column `b`, which will ensure the time difference is < 10 minutes
* If both columns are `None`, fill them with `pandas.Timedelta(0)`

```py
import pandas as pd
import numpy as np
from datetime import timedelta

a = ['2017-12-31 16:00:00-08:00', '2017-12-31 17:00:00-08:00', '2017-12-31 18:00:00-08:00', None]
b = ['2017-12-31 17:00:00-08:00', None, '2017-12-31 18:00:10-08:00', None]

# dataframe
df = pd.DataFrame({'a': a, 'b': b})

# convert columns to datetime format
df[['a', 'b']] = df[['a', 'b']].apply(pd.to_datetime)

                          a                         b
0 2017-12-31 16:00:00-08:00 2017-12-31 17:00:00-08:00
1 2017-12-31 17:00:00-08:00                       NaT
2 2017-12-31 18:00:00-08:00 2017-12-31 18:00:10-08:00
3                       NaT                       NaT

# fillna in column b with values from column a
df.b = df.b.fillna(df.a)

# if both columns are None, fillna with Timedelta(0)
df[['a', 'b']] = df[['a', 'b']].fillna(pd.Timedelta(0))

                           a                          b
0  2017-12-31 16:00:00-08:00  2017-12-31 17:00:00-08:00
1  2017-12-31 17:00:00-08:00  2017-12-31 17:00:00-08:00
2  2017-12-31 18:00:00-08:00  2017-12-31 18:00:10-08:00
3            0 days 00:00:00            0 days 00:00:00

# function
def date_check(x, y):
    return (np.abs(x - y)) < timedelta(minutes=10)

# function call
date_check(df.a, df.b)
[out]:
0    False
1     True
2     True
3     True
dtype: bool

# add a column to the dataframe
df['time_diff'] = np.abs(df.a - df.b) < pd.Timedelta(minutes=10)

                           a                          b  time_diff
0  2017-12-31 16:00:00-08:00  2017-12-31 17:00:00-08:00      False
1  2017-12-31 17:00:00-08:00  2017-12-31 17:00:00-08:00       True
2  2017-12-31 18:00:00-08:00  2017-12-31 18:00:10-08:00       True
3            0 days 00:00:00            0 days 00:00:00       True

```
It can't perform the operations on `NoneTypes` so just handle separately with a try/except block.

```
def date_check(x, y):
    try:
        return (np.abs(x - y)) > timedelta(minutes=10)
    except:
        return True

```