First, I made this one a while back as a final projects for the vets in tech intro to python course, available to mil folks for like $10. so my memory is a bit spotty on this one, but you should check out ViT’s eventbrite page for CHEAP, FANTASTIC tech courses taught by folks like me.
Now that that’s out of the way, let’s talk a little bit about this project.
The Consumer Financial Protection Bureau (CFPB) is a U.S. government agency established with the primary mission of protecting consumers in the financial marketplace. Created in response to the 2008 financial crisis, the CFPB works to ensure that financial products and services are fair, transparent, and competitive. It exercises regulatory oversight over banks, credit unions, and other financial institutions, enforcing laws that safeguard consumers from deceptive practices and promoting financial literacy. The CFPB aims to empower consumers to make informed financial decisions and address issues related to mortgages, credit cards, student loans, and various other financial products.
from chatgpt (thanks)
the CFPB maintains an api of its consumer complaints database; find it here. tbh, i didnt review the documentation extensively so you’ll want to do that in the event that you find all of this useful. refer to the api docs for some information about that.
the challenge is parsing that api, which returns a json file that looks a little something like this:
{
"_shards": {
"failed": 0,
"skipped": 0,
"successful": 5,
"total": 5
},
"aggregations": {
"issue": {
"doc_count": 1,
"issue": {
"buckets": [
{
"doc_count": 1,
"issue": {
"buckets": [],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
},
"key": "Problem when making payments"
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
}
},
"product": {
"doc_count": 1,
"product": {
"buckets": [
{
"doc_count": 1,
"key": "Payday loan, title loan, personal loan, or advance loan",
"product": {
"buckets": [
{
"doc_count": 1,
"key": "Installment loan"
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
}
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
}
},
"state": {
"doc_count": 5,
"state": {
"buckets": [
{
"doc_count": 3,
"issue": {
"buckets": [
{
"doc_count": 2,
"key": "Problem with a credit reporting company's investigation into an existing problem"
},
{
"doc_count": 1,
"key": "Improper use of your report"
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
},
"key": "IL",
"product": {
"buckets": [
{
"doc_count": 3,
"key": "Credit reporting, credit repair services, or other personal consumer reports"
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
}
},
{
"doc_count": 1,
"issue": {
"buckets": [
{
"doc_count": 1,
"key": "Problem when making payments"
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
},
"key": "NY",
"product": {
"buckets": [
{
"doc_count": 1,
"key": "Payday loan, title loan, personal loan, or advance loan"
}
],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0
}
},
So yeah, that’s a bit of a mouthful, eh. I’m sure it makes more sense to someone who works with it on a daily/regular basis; yet I am not that person, so it doesn’t. Let’s turn that into an Excel file!
You’ll need to install & import json, requests, and openpyxl. You’ll want to get your user to input a state and a search term. we will inject these into a provided url to pull our json file as needed. Looks like this. Also, you can change the dates on this, or make them an input too:
url = "https://www.consumerfinance.gov/data-research/consumer-complaints/search/api/v1/geo/states?search_term=" + search_term + \
"&field=complaint_what_happened&company_received_min=2022-09-26&date_received_min=2022-09-26" + state_url
So yeah, that’s that. Man, looking back at my code it was a bit of a pita. but it produces an xlsx file which is nice. Let’s look up instances of ‘predatory’ in the state of Alabama.
Okay, one thing I forgot was in there is that we connect to the Kanye Rest API to pull the name of our sheet then append the state at the end of it. I used to be so funny back then…
Here is a snip of our prompt:
And here’s the output, as seen in the VS Code viewer:
Perhaps you should have been more like water today in Alabana, Kanye.
So where does this get us? I think that the state column refers to either the origin or destination of the complaint, or the home state of the entity being complained about? Maybe. I has to be in the docs somewhere, but IDK where. Each of the headers show the TYPES of complaints which have predatory in their contents.
From here you can do all sorts of analysis, comparing states to one another or to themselves over time. You can look at ratio of complaint types, or per capita complaint rates, or maybe even think of a more useful search term that actually makes sense in this context. You can use something like bokeh to visualize something, or something like llamaindex to create an archive of these flat files and query them using plain english. The possibilities are endless!
Well, I am already bored of this. This is an old project created in response to a prompt to connect to an API and I chose a boring one, but maybe it will be useful to someone. I need to code more often now that I am done with my posts.
What a long week with snow days and sick days. Ugh!
Title: ‘CFPB Predatory in Alabama’
0 Comments