У меня есть четыре таблицы: predicted_tags
, actual_tags
, tags_names
и news_text
.
В таблицах predicted_tags
и actual_tags
имена строк являются тегами id. В этих таблицах 1
означает True, а 0
означает False.
Форма predicted_tags
и actual_tags
(23413, 1369).
predicted_tags
print(predicted_tags)
+-------+-----+---+-----+------+------+
| | 1 | 3 | ... | 8345 | 8347 |
+-------+-----+---+-----+------+------+
| 35615 | 0 | 0 | ... | 1 | 0 |
| 58666 | 1 | 0 | ... | 0 | 0 |
| 16197 | 0 | 0 | ... | 0 | 1 |
| 68824 | 0 | 0 | ... | 1 | 1 |
| 22277 | 0 | 0 | ... | 1 | 0 |
+-------+-----+---+-----+------+------+
actual_tags
print(actual_tags)
+-------+-----+---+-----+------+------+
| | 1 | 3 | ... | 8345 | 8347 |
+-------+-----+---+-----+------+------+
| 35615 | 0 | 0 | ... | 1 | 0 |
| 58666 | 1 | 1 | ... | 0 | 0 |
| 16197 | 0 | 0 | ... | 0 | 1 |
| 68824 | 0 | 0 | ... | 1 | 1 |
| 22277 | 0 | 1 | ... | 1 | 0 |
+-------+-----+---+-----+------+------+
tags_names
print(tags_names)
+--------+----------+-------------+
| | tag_id | tag_name |
+--------+----------+-------------+
| 127579 | 1 | politics |
| 108814 | 3 | economics |
| ... | ... | ... |
| 18 | 8345 | hot |
| 257141 | 8347 | environment |
+--------+----------+-------------+
news_text
:
print(news_text)
+----------+------------------------+-----------------------------+
| | news_name | news_content |
+----------+------------------------+-----------------------------+
| 35615 | Secret of… | Hi! Today I will talk... |
| 58666 | Conversations with a … | I have a big experience... |
| 16197 | Harm of alcohol | Today, we… |
| ... | ... | ... |
| 68824 | Hot news | Celebrity with... |
| 22277 | Finance market | Last week… |
+----------+------------------------+-----------------------------+
Я хочу получить следующую таблицу:
+-------+------------------------+----------------------------+------------------------+---------------------------+
| | news_name | news_content | predicted_tags | actual_tags |
+-------+------------------------+----------------------------+------------------------+---------------------------+
| 35615 | Secret of… | Hi! Today I will talk... | ['hot'] | ['hot'] |
| 58666 | Conversations with a … | I have a big experience... | ['politics'] | ['politics', 'economics'] |
| 16197 | Harm of alcohol | Today, we… | ['environment'] | ['environment'] |
| 68824 | Hot news | Celebrity with... | ['hot', 'environment'] | ['hot', 'environment'] |
| 22277 | Finance market | Last week… | ['hot'] | ['hot', 'economics'] |
+-------+------------------------+----------------------------+------------------------+---------------------------+
Как я могу сделать это, используя Панд?