0

I have a DataFrame with info about entries of words in a book chapters.

Word Chapters
table 1, 3, 8
apple 2, 3
work 5, 8

I am to get new DataFrame where every entry will get a single row:

idWord idChapter
1 1
1 3
1 8
2 2
2 3
3 5
3 8

and then export it to SQLite receiving the 3NF database.

I'm new in pandas. I found this task is connected with split() so I tried this:

df_entry[['idword', 'idchapter']] = df['Chapters'].str.split(' ', 1, expand=True)

and received

     idword              idchapter
0        1,                   3, 8
1        2,                      3
2        5,                      8

But how can I put here df['Word'] column? I thought about this:

df_entry[['idword', 'idchapter']] = [df['Word'], [df['Chapters'].str.split(',', 1, expand=True)]]

and this:

dict = {[[ch for ch in df[w]['Chapters'].str.split(',')] for w in df['Word']]}

but all these have syntax errors. Please help!

0 Answers0