To filter the CSV data based on your criteria using Python, you can use the pandas library, which is great for handling and analyzing data. Here's how you can do it:
-
Install pandas: If you haven't already, you need to install pandas. You can do this by running pip install pandas in your command line or terminal.
-
Filtering the Data: You want to keep rows where either:
- The "Date of Enrollment" ends in 2023,
- The "Exit Date" ends in 2023,
- Or the "Exit Date" is blank.
Here is a Python script that demonstrates how to accomplish this:
import pandas as pd
# Load the CSV file
df = pd.read_csv('path_to_your_file.csv')
# Convert the 'Date of Enrollment' and 'Exit Date' to string for easier manipulation
df['Date of Enrollment'] = df['Date of Enrollment'].astype(str)
df['Exit Date'] = df['Exit Date'].astype(str)
# Filter based on your conditions
filtered_df = df[
(df['Date of Enrollment'].str.endswith('2023')) | # Date of Enrollment ends in 2023
(df['Exit Date'].str.endswith('2023')) | # Exit Date ends in 2023
(df['Exit Date'] == '') # Exit Date is blank
]
# Save the filtered data to a new CSV file
filtered_df.to_csv('filtered_file.csv', index=False)
Make sure to replace 'path_to_your_file.csv' with the actual path to your CSV file. This script reads your CSV, filters the rows according to your criteria, and then saves the filtered data into a new file named 'filtered_file.csv'.
Remember, this script assumes that your dates are formatted in a way that the year appears at the end of the "Date of Enrollment" and "Exit Date" fields. If your date format is different, you might need to adjust the filtering logic accordingly.