Question: I'm using an sqlite db to populate an ios app with data about irregular verbs -- it's a language learning app.

The db has 3 tables, verb categories, verbs, and verb elements. The last has one entry per verb termination, so 50-odd per verb. The total db is about 2,500 entries, each one has 3-5 short string fields.

My question is whether the best thing to do from a performance point of view is:

(1) - write structs to model the data, each with appropriate functions, and load the db into memory in the form of structs when the app initialises, OR
(2) - write functions to query the sqlite db on the fly for each new view

My guess is that (1) is much better for a small db of this size, but I thought I would consult your collective wisdom as I'm a novice. Thanks in advance for any advice.

Btw, this is a follow up question to one I asked about how to get data into an ios app:

[What's the best practice for storing and importing (non-user) data for an iOS app in swift/swiftUI/Xcode?](https://stackoverflow.com/questions/71845216/whats-the-best-practice-for-storing-and-importing-non-user-data-for-an-ios-ap/71845932?noredirect=1#comment126961713_71845932)

Answer: 
First step is [`GroupBy.cumcount`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumcount.html) with [`DataFrame.pivot`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pivot.html):

```
df['Date purchase'] = pd.to_datetime(df['Date purchase'])
df1 = (df.sort_values(by=['ID number', 'Date purchase'], ascending=[True, False])
         .assign(g=lambda x: x.groupby('ID number').cumcount())
         .pivot('ID number','g','Date purchase')
         .rename(columns = lambda x: f'Date {x + 1}'))
print (df1)
g             Date 1     Date 2     Date 3
ID number                                 
1         2022-05-01 2021-03-03 2020-01-03
2         2019-01-03 2018-01-03        NaT

```

Then for differencies between columns use [`DataFrame.diff`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.diff.html):

```
df2 = df1.diff(-1, axis=1)
print (df2)
g           Date 1   Date 2 Date 3
ID number                         
1         424 days 425 days    NaT
2         365 days      NaT    NaT

```

If need averages:

```
df3 = df1.apply(pd.Series.mean, axis=1).reset_index(name='Avg Dates').rename_axis(None, axis=1)
print (df3)
   ID number           Avg Dates
0          1 2021-03-02 16:00:00
1          2 2018-07-04 12:00:00

```
Could you do something like this?

```py
def format_dataframe(df):
    """
    Function formats the dataframe to the following:
    | ID number| Date 1         | Date 2         | Date 3         |
    | -------- | -------------- | -------------- | -------------- |
    | 1        | 2022-05-01     | 2021-03-03     | 2020-01-03     |
    | 2        | 2019-01-03     | 2018-01-03     |                |
    """
    df = df.sort_values(by=['ID number', 'Date purchase'])
    df = df.drop_duplicates(subset=['ID number'], keep='first')
    df = df.drop(columns=['Date purchase'])
    df = df.rename(columns={'ID number': 'ID number', 'Date 1': 'Date 1', 'Date 2': 'Date 2', 'Date 3': 'Date 3'})
    return df

```