Как преобразовать текстовую статью с ключевыми словами в фрейм данных Pandas - PullRequest
0 голосов
/ 22 июня 2019

У меня есть текстовые файлы, подобные приведенным ниже, около 5000 раз, и я хочу извлечь текстовую статью в один столбец df, а ключевые слова в списке - в другой столбец df. Мне нужно это, чтобы иметь больше тренировочных данных.

В приведенном ниже примере статья, которую я хочу извлечь, содержит все: от «Аддис-Абеба» до «частный банк», и все ключевые слова - это ключевые слова после «СУБЪЕКТА» без процентов в скобках.

Образец набора данных:



                                 Addis Fortune

                                 February 2011

Declaration? AU Action Needed in Favour of Democracy [opinion]

LENGTH: 692  words


Addis Abeba has been hosting delegates and heads of state for the AU Summit. It
is encouraging to see leaders of Africa discussing issues of continental
importance that accelerate the process of integration and thereby put Africa in
a better bargaining position in its relations with the outside world.

Indeed, "United We Stand, Divided We Fall."

It is time that the AU took a bold step to ensure that the leaders of the
continent win the hearts and minds of their citizens. It should ensure the
existence of democratic governments, which, at a minimum, guarantee popular
participation based on an acceptance of political equality among all citizens,
respect for civil liberties, and meaningful checks and balances on the power of
the executive.

This is also indispensable to the realisation of the age-old dream of the
formation of the United States of Africa. Donor countries and organisations also
have moral obligations to extend much needed support in this aspect.

Dawit Haile is a loan officer at a private bank.

SUBJECT: HEADS OF STATE & GOVERNMENT (90%); ELECTIONS (90%); INTERNATIONAL
ASSISTANCE (89%); INTERNATIONAL RELATIONS (73%); GROSS DOMESTIC PRODUCT (70%);
ECONOMIC NEWS (70%); EMBEZZLEMENT (68%); ELECTION FRAUD (68%) Ethiopia;
International Organizations and Africa

GEOGRAPHIC: AFRICA (96%); EGYPT (93%); UNITED STATES (93%); CHINA (92%);
ETHIOPIA (79%); TUNISIA (79%); ISRAEL (79%) Africa

LOAD-DATE: February 8, 2011

LANGUAGE: ENGLISH

PUBLICATION-TYPE: Newspaper


                     Copyright 2011 AllAfrica Global Media.
                              All Rights Reserved


                              2 of 1352 DOCUMENTS


                                 Addis Fortune

                                 February 2011

Gebrekidan Beyene's Prosecutors Repeat Request for 25 Years

BYLINE: Eden Sahle

LENGTH: 815  words


During the appeals hearing last week of Gebrekidan Beyene, a.k.a. Morocco,
general manager and a shareholder of a private limited company by the same name,
prosecutors of the Ethiopian Revenues and Customs Authority (ERCA) requested
almost the same sentence they originally had, in August 2010: a maximum jail
term and confiscation of properties.

However, the lower court's decision to mitigate the sentence was correct and the
Appeals Bench should release Gebrekidan, either as a free man or on parole, the
defence argued. His good behaviour in prison and the investment he had made in
his country should be counted as mitigating circumstances, the lawyer claimed,
also counting the defendant's poor health in mitigation. The case was adjourned
for a verdict until May 2, 2011.

An alleged similar offence involving money laundering and loan sharking against
Ayalew Tesema, board chairman and major shareholder of Ayat Real Estate, is
underway at the Federal High Court.

SUBJECT: LITIGATION (91%); JUSTICE DEPARTMENTS (90%); BANKING & FINANCE (90%);
EXCISE & CUSTOMS (90%); LIMITED LIABILITY COMPANIES (90%); SENTENCING (90%);
APPEALS (89%); LAW COURTS & TRIBUNALS (89%); JAIL SENTENCING (89%); LAWYERS
(89%); VERDICTS (89%); SUPREME COURTS (89%); FINES & PENALTIES (89%);
SETTLEMENTS & DECISIONS (78%); CRIMINAL CONVICTIONS (78%); DECISIONS & RULINGS
(78%); PRISONS (77%); SUITS & CLAIMS (77%); VALUE ADDED TAX (77%); JUDGES (73%);
INCOME TAX (72%); MONEY LAUNDERING (69%); COUNTERFEITING (68%); INTEREST RATES
(55%); ECONOMIC NEWS (55%) Ethiopia; Legal and Judicial Affairs

GEOGRAPHIC: MOROCCO (90%)

LOAD-DATE: March 1, 2011

LANGUAGE: ENGLISH

PUBLICATION-TYPE: Newspaper

Мой ожидаемый результат будет:

df
    content             keywords
1   'string article 1'  [HEADS OF STATE & GOVERNMENT, ELECTIONS, ...]
2   'string article 2'  [LITIGATION, JUSTICE DEPARTMENTS, ...]
...