I have 2 list of string containing pitch value:
pitch_detected = ['A#3 / Bb3', 'B3', 'C4', 'C#4 / Db4', 'D4', 'D#4 / Eb4', 'E4', 'F4']
pitch_dataset = ['G#3 / Ab3', 'A#3 / Bb3', 'B3', 'C4', 'C#4 / Db4', 'D4', 'D#4 / Eb4', 'E4', 'F4', 'F#4 / Gb4', 'G4']
I need to print them at HTML page later. Right now, I use this code, and I face no problem.
df = pd.DataFrame(data = [pitch_dataset, pitch_class])
df.index = ['Pitch from dataset', 'Pitch detected']
df = df.T
table_result = df.to_html()
This is the current HTML output created from dataframe df
.
Altough the output is looking nicely, I need to present it with some conditions. I think, this can be achieved by manipulating the DataFrame first before printing to HTML using to_html()
. Here are the conditions:
- If pitch X is present in both
pitch_dataset
andpitch_detected
, the pitch X will be shown side-by-side. - If pitch X is present in
pitch_dataset
but not present inpitch_detected
, the row inpitch_detected
will be filled by-
. - If pitch X is not present in
pitch_dataset
but present inpitch_detected
, the pitch X will be shown inpitch_detected
column, the extra rows inpitch_dataset
will be filled by-
.
Is there any way to achieve this condition with Python?
This is the sample desired output I want, generated by Microsoft Excel, with comments on condition. Condition 1 and 2 is the same as the output table given above, while condition 3 is manually made for the purpose of giving examples, with the pitch_detected
list would be:
pitch_detected = ['A#3 / Bb3', 'B3', 'C4', 'C#4 / Db4', 'D4', 'D#4 / Eb4', 'E4', 'F4', 'A4', 'B4']
At the real output, I require no highlighting.
Edit: because I have received notification of a duplicate question here, I need to address that the problem I face is different from the suspected duplicate question.