klieret / AnkiPandas

Analyze and manipulate your Anki collection using pandas! 🌠🐼
https://ankipandas.rtfd.io/
MIT License
133 stars 18 forks source link

aquery method #23

Open klieret opened 5 years ago

klieret commented 5 years ago

Easy to use method that can perform most selections.

With options:

??

or should we have is_... methods instead?

Maybe?

dodokpeter commented 3 years ago

What I miss is clear path from cards to notes, f.e. I've got a list of nid (notes id), which I query from cards and then perform cards selection, something like:

nids = cards[cards.cdeck == 'DECK"].nid.tolist()
notes[notes.id in nids] 

If this is even possible, it's not written in documentation

klieret commented 3 years ago

Hi @dodokpeter . So you're asking about the general case of having a list of note ids and wanting to retrieve the corresponding rows from the notes table (I'm a bit confused because you wrote that you want to select cards, but then start with notes[notes.id...])?

You can do this as follows:

# note IDs gotten e.g. from a query on cards
nids = [ 1299250735320, 1299250735321]
# get a DataFrame of rows for these note IDs
relevant_notes = notes.loc[nids]

It's not documented in ankipandas, because it's a standard feature of pandas. You can find a bit more information here: indexing in pandas, dataframe.loc

Does that help?

dodokpeter commented 3 years ago

thanks, it helped, I am a new in pandas, so I didn't know this