Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Created August 7, 2023 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoodnessEzeokafor/2b6e27e9dc827a2b5d0e95312741ec5b to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/2b6e27e9dc827a2b5d0e95312741ec5b to your computer and use it in GitHub Desktop.
Searching through a csv file
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