I am trying to parse a section from 10K in Edgar database, when I run the following code,
# pip install edgartools
import pandas as pd
from edgar import *
# Tell the SEC who you are
set_identity("Your Name youremail@outlook.com")
filings2 = get_filings(form='10-K', amendments=False,
filing_date="2024-03-01")
filings2_df = filings2.to_pandas()
# Create a list to store the Item 1c text
item1c_texts = []
# Iterate over each filing
for filing in filings2:
url = filing.document.url
cik = filing.cik
filing_date = filing.header.filing_date,
reporting_date = filing.header.period_of_report,
comn = filing.company
# Extract the text for Item 1c
TenK = filing.obj()
item1c_text = TenK['Item 1C']
item1c_texts.append({
'CIK': cik,
'Filing Date': str(filing_date),
'Item 1c Text': item1c_text,
'url': url,
'reporting_date': str(reporting_date),
'comn': comn
})
# Create a DataFrame from the Item 1c text data
item1c_df = pd.DataFrame(item1c_texts)
I got this error -
TypeError: cannot unpack non-iterable NoneType object
Cell In[463], line 11
9 if TenK is not None:
10 TenK = filing.obj()
---> 11 item1c_text = TenK['Item 1C']
12 item1c_texts.append({
13 'CIK': cik,
14 'Filing Date': str(filing_date),
(...)
18 'comn': comn
19 })
Show Traceback
Is there any way I can bypass the non-iterable NoneType issue? I read about many other NoneType issues in this platform, but none of them is very helpful for me.
It seems that Item_1C is not available for some of them. You can use try/exception to bypass when the value is not found.
for n, filing in enumerate(filings2):
url = filing.document.url
cik = filing.cik
filing_date = filing.header.filing_date,
reporting_date = filing.header.period_of_report,
comn = filing.company
# Extract the text for Item 1c
TenK = filing.obj()
# Bypass None values
try:
item1c_text = TenK['Item 1C']
except:
item1c_text = None
# Append the data to the list
# item1c_text = TenK['Item 1C']
item1c_texts.append({
'CIK': cik,
'Filing Date': str(filing_date),
'Item 1c Text': item1c_text,
'url': url,
'reporting_date': str(reporting_date),
'comn': comn
})
It appears that five of them are missing.