Created
August 7, 2023 13:27
-
-
Save GoodnessEzeokafor/2b6e27e9dc827a2b5d0e95312741ec5b to your computer and use it in GitHub Desktop.
Searching through a csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# Load the data from the CSV file into a DataFrame | |
file_path = "data.csv" # Replace with the actual path to your CSV file | |
df = pd.read_csv(file_path) | |
# Get user input for the search criteria | |
search_input = input("Enter the value you want to search for: ") | |
# Filter the DataFrame based on the search criteria | |
result = df[df.apply(lambda row: row.astype(str).str.contains(search_input, case=False).any(), axis=1)] | |
# Print only the specified columns | |
columns_to_print = ['txref', 'txid', 'flwref', 'raveref', 'custemail', 'amount', 'currency', 'status', 'paccountfirstname', 'paccountlastname'] | |
print(result[columns_to_print]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment