Merging Fields From Notes - ghrgriner/anki-stats GitHub Wiki

There is example code in custom_output.py for merging to exported notes data.

Here we assume the notes file is exported from the companion exporter add-on.

In this example, our notes file has a field n_exprs that we want to merge to the cards dataset. For example, we could be studying a foreign language and have put multiple expressions using a word on the back side of a vocabulary card. In this case, we might be interested in seeing how card difficulty varies by n_expr. However, in the example below, we simply print the frequency distribution after merging to the cards data frame.

    # Here, we show how to merge notes that are exported by the companion
    # exporter. We have renamed the output notes file (default name is:
    # [NoteType]___[NoteTypeId].csv) to notes.csv. 'nid' will always be
    # present, as this is from the Anki database. The field `n_exprs` is
    # the field in our notes that we want to merge. Multiple merges may
    # be required if the cards data frame contains more than one type of
    # note.

    df_notes = pd.read_csv('input/notes.csv', sep='\t', quotechar='"',
                     index_col=False)
    df_cards = df_cards.merge(df_notes['nid','n_exprs'](/ghrgriner/anki-stats/wiki/'nid','n_exprs'), how='left',
                  left_on='c_nid', right_on='nid')
    freq(df_cards, 'n_exprs', title='Number of expressions', dropna=False)

We haven't provided code for merging note information when INPUT_MODE = INPUT_MODE_SQLITE. In this case, the user will have to get the notes information from the notes table and the field names from the notes from the notetypes table. The user can then compile the notes.proto and notetypes.proto and include the generated pb2 file in their Python program. Classes can then be instantiated to access the data. See the instructions for extracting FSRS parameters for details.