I am trying to extract a specific portion of text from my "text" variable in a dataframe and need some help!
I have the current DataFrame:
| file_path | file_name | text |
|---|---|---|
| /Users/user/Dropbox/SEC investigat... | _0000886982_18795_2687.txt | 0000950123-11-059690.txt : 20110... |
| /Users/user/Dropbox/SEC investigat... | _0001068875_16706_4152.txt | 0001193125-05-191846.txt : 20050... |
I am trying to extract a portion of text from the "text" variable in Python that always follows a line starting with "Item 5.02".
I need the text between the "Item 5.02" line and the first occurrence of any of the following terms: "Item 8.01", "Item 9.01", or "SIGNATURES". There are occurrences in which the text might not have an "Item 8.01", but might include "Item 9.01". There are also occurrences in which it might have all of the terms. There will always be at least one of these terms following the "Item 5.02" line. Additionally, the text between the "Item 5.02" line and one of the terms could be in multiple paragraphs. I just need the text between the line starting with "Item 5.02" and the first occurrence of one of the terms!
Here is an example of an occurrence in which the "Item 5.02" line is followed by an "Item 9.01" line:
Item 5.02 Departure of Directors or Certain Officers; Election of Directors; Appointment of Certain Officers; Compensatory Arrangement of Certain Officers.
On September 29, 2015, AAR CORP. (the Company) announced that Michael J. Sharp was elected Chief Financial Officer of the Company on September 28, 2015, with such election to be effective on October 5, 2015. Mr. Sharp will replace John C. Fortson, who is resigning effective October 5, 2015 to take a Chief Financial Officer position with a non-aviation company.
Mr. Sharp, 53, is a 19-veteran of the Company and will continue to serve as the Companys Vice President and Chief Accounting Officer. Mr. Sharp previously served as interim Chief Financial Officer of the Company from October 2012 to July 2013. Prior to joining the Company, Mr. Sharp worked in management positions with Kraft Foods and KPMG, LLP.
As Chief Financial Officer of the Company, Mr. Sharp will receive the following compensation for the fiscal year ending May 31, 2016: an annual base salary of $400,000; an annual cash bonus opportunity equal to 70% of his annual base salary if certain performance goals are met at a target level; and total stock awards valued at $500,000 on the date of grant. Mr. Sharp continues to be eligible for other benefits provided to executive officers of the Company as described in the Companys proxy statement filed with the Securities and Exchange Commission on August 28, 2015. Mr. Sharp has a severance and change in control agreement with the Company (see Exhibit 10.10 to the Companys annual report on Form 10-K for the fiscal year ended May 31, 2001).
A copy of the Companys press release announcing Mr. Sharps appointment is attached hereto as Exhibit 99.1 and is incorporated herein by reference.
Item 9.01 Financial Statements and Exhibits.
I would like to extract the following:
On September 29, 2015, AAR CORP. (the Company) announced that Michael J. Sharp was elected Chief Financial Officer of the Company on September 28, 2015, with such election to be effective on October 5, 2015. Mr. Sharp will replace John C. Fortson, who is resigning effective October 5, 2015 to take a Chief Financial Officer position with a non-aviation company. Mr. Sharp, 53, is a 19-veteran of the Company and will continue to serve as the Companys Vice President and Chief Accounting Officer. Mr. Sharp previously served as interim Chief Financial Officer of the Company from October 2012 to July 2013. Prior to joining the Company, Mr. Sharp worked in management positions with Kraft Foods and KPMG, LLP. As Chief Financial Officer of the Company, Mr. Sharp will receive the following compensation for the fiscal year ending May 31, 2016: an annual base salary of $400,000; an annual cash bonus opportunity equal to 70% of his annual base salary if certain performance goals are met at a target level; and total stock awards valued at $500,000 on the date of grant. Mr. Sharp continues to be eligible for other benefits provided to executive officers of the Company as described in the Companys proxy statement filed with the Securities and Exchange Commission on August 28, 2015. Mr. Sharp has a severance and change in control agreement with the Company (see Exhibit 10.10 to the Companys annual report on Form 10-K for the fiscal year ended May 31, 2001). A copy of the Companys press release announcing Mr. Sharps appointment is attached hereto as Exhibit 99.1 and is incorporated herein by reference.
So far, I have the following code which does not account for all of the terms, and only pulls the first paragraph following the "Item 5.02" line. Code:
def extractPassage(text):
lines = text.split("\n\n")
for i,line in enumerate(lines):
if line.startswith("Item 5.02"):
return lines[i+1]
#raise Exception("No line found starting with Item 5.02")
pd_00['important_text'] = pd_00['text'].apply(extractPassage)
All help is extremely appreciated!