> ## Content Index
> Fetch the complete content index at: https://www.bambooweekly.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Bamboo Weekly #52: Border encounters
- URL: https://www.bambooweekly.com/bw-52-border-encounters/
- Published: 2024-02-07T16:01:17.000Z
- Updated: 2026-08-06T10:45:31.000Z
- Description: Get better at: CSV, dates and times, plotting, grouping, multi-indexes, and stack-unstack.
- Author: Reuven M. Lerner
- Tags: csv, datetime, plotting, grouping, multi-index, stack-unstack

*\[Administrative note: Office hours for paid Bamboo Weekly subscribers will take place on Sunday. Come with any and all questions about Pandas! I’ll send a note with the Zoom link in the coming days.\]*

The Biden administration has committed to providing military aid to Ukraine, Israel, and Taiwan. Of course, it can't do so unless Congress approves such spending; for the most part, Democrats want to approve this spending, while Republicans don't.

A number of senators and representatives put together a compromise bill that would give Democrats foreign military aid, and Republicans money to secure the border further. However, this bill died over the last few days, thanks in no small part to Donald Trump, who told Republicans in Congress to oppose it. Biden has, shrewdly and correctly, already started to point out the hypocrisy of Republicans claiming to want to strengthen the border, but then failing to approve funding to do so when given the chance. A New York Times articles describing the situation is here: [https://www.nytimes.com/2024/02/06/us/politics/border-republicans-ukraine-bill.html?unlocked\_article\_code=1.Tk0.xjzW.OJCxWbtkBliH&bgrp=c&smid=url-share](https://www.nytimes.com/2024/02/06/us/politics/border-republicans-ukraine-bill.html?unlocked%5Farticle%5Fcode=1.Tk0.xjzW.OJCxWbtkBliH&bgrp=c&smid=url-share&ref=bambooweekly.com)

How many people are really crossing into the US? Where are these people from? And what changes have we seen over time? This week, we’ll examine this data, digging into a topic that has been at the top of the headlines.

### Data and nine questions

Borders in the United States are regulated by the Department of Homeland Security's Customs and Border Protection (CBP). They describe "border encounters" as events when their agents come across a non-citizen who isn't allowed to be in the US. There are three different possible results of an encounter:

- Expulsion: The person is removed from the US without a hearing of any sort, either to their home country or to the country from which they entered the United States,
- Apprehension: The person is found when trying to enter the US illegally. They are usually processed further, which might mean hearings, background checks, and claims of asylum or refugee status.
- Inadmissible: The person tries to enter at an established port of entry, and isn't allowed into the US. Again, people at this stage can claim asylum or refugee status.

Our data is a CSV file provided by CBP describing border encounters starting in fiscal year 2021\. The main page for downloading the data is at

[https://www.cbp.gov/document/stats/nationwide-encounters](https://www.cbp.gov/document/stats/nationwide-encounters?ref=bambooweekly.com)

The file that we'll be examining shows information from fiscal year 2021 through fiscal year 2024, ending in December of FY 2024:

[https://www.cbp.gov/sites/default/files/assets/documents/2024-Jan/nationwide-encounters-fy21-fy24-dec-aor.csv](https://www.cbp.gov/sites/default/files/assets/documents/2024-Jan/nationwide-encounters-fy21-fy24-dec-aor.csv?ref=bambooweekly.com)

You can get a complete data dictionary from:

[/content/files/sites/default/files/assets/documents/2023-Sep/nationwide-encounters-data-dictionary.pdf](https://www.bambooweekly.com/content/files/sites/default/files/assets/documents/2023-Sep/nationwide-encounters-data-dictionary.pdf)

Note that you might need to go to the main page in order to download these documents; at least some of the time, I was unable to retrieve them via a direct link.

This week's learning goals include working with dates (including turning fiscal years into calendar years), grouping, resampling, window functions, and plotting.

Here are my 9 tasks annd questions for you. I’ll be back tomorrow with my complete solutions and Jupyter notebook.

- Read the data from the CSV file into a data frame. Convert "2024 FYTD" into just "2024".
- Create a "date" new column, based on the "Fiscal Year" and "Month (abbv)" columns, containing a datetime value for that year and month based on the fiscal year. Make that the index.
- Create a line plot showing, month by month, the total number of people caught by the US government. What's weird or wrong about this graph?
- Convert the index from using fiscal years to using calendar years. This means that any date in October, November, or December should have its year reduced by 1.
- Rerun the plot from question 3\. What sort of trend do you see?
- Now draw three lines on the same plot showing, over time, the total number of people caught by the US government in each of the three "Encounter Type" values.
- Create a data frame with one row for each country of citizenship reported by CBP, and one column for each year in the data set. The values should reflect the percentage of people from each country encountered in each year. (That is, each column should sum to 1.0.)
- Calculate the degree by which these percentages have changed in the last year. Which countries have shown the greatest increase, as a percentage, in the number of people encountered by CBP? Which have shown the greatest decrease?
- We hear about unaccompanied minors coming from other countries into the United States. In 2023, from what 10 countries did the greatest number of unaccompanied minors enter the US?

I’ll be back tomorrow with my detailed solutions, including my Jupyter notebook.

Until then,

Reuven