如何将带有关键字的文本文章转换为熊猫数据框

时间:2019-06-22 08:20:18

标签: python nlp text-processing

我下面有类似的文本文件,大约有5,000次,我想将文本文章提取到一个df列,并将列表中的关键字提取到另一个df列。我需要更多训练数据。

在下面的示例中,我要提取的文章是从“亚的斯亚贝巴”到“私人银行”的所有内容,关键字都是“ SUBJECT”之后的所有关键字,没有括号。

数据集样本:



                                 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, ...]

0 个答案:

没有答案