Bis Micro Project
Bis Micro Project
Submitted by
Student of
Diploma In Engineering
in
computer Department
Step-by-Step Explanation
Importing Libraries:
o import pandas as pd
o The code begins by importing the pandas library, which is essential fo data
manipulation and analysis in Python.
data = {
'time': ['2023-10-01 10:00', '2023-10-01 10:05', '2023-10-01 10:10', '2023-10-01 10:15', '2023-10-01 10:20'],
}
transaction_id amount location time user_id
1 100 USA 2023-10-01 10:00 101
2 1500 USA 2023-10-01 10:05 101
3 200 Canada 2023-10-01 10:10 102
4 3000 USA 2023-10-01 10:15 101
5 50 Canada 2023-10-01 10:20 102
A dictionary named data is created, containing sample transaction information.
Each key represents a column in the dataset:
o transaction_id: Unique identifier for each transaction.
CREATING A DATAFRAME:
o transactions = pd.DataFrame(data)
o This structure allows for easy manipulation and analysis of the transaction data.
fraud_cases = []
DataFrame as input and initializes an empty list fraud_cases to store any detected fraud
cases.
o The function iterates over each transaction in the DataFrame using iterrows(), which returns
both the index and the row data.
o For each transaction, it checks if the amount exceeds the defined amount_threshold. If it
does, a tuple containing the transaction_id and the reason ('High transaction amount') is
appended to the fraud_cases list.
if not recent_transactions.empty:
time_diff = pd.to_datetime(row['time']) - pd.to_datetime(recent_transactions['time'].max())
import pandas as pd
data = {
'time': ['2023-10-01 10:00', '2023-10-01 10:05', '2023-10-01 10:10', '2023-10-01 10:15', '2023-10-01
10:20'],
# Create a DataFrame
transactions = pd.DataFrame(data)
def detect_fraud(transactions):
fraud_cases = []
if not recent_transactions.empty:
return fraud_cases
fraudulent_transactions = detect_fraud(transactions)
# Output results
if fraudulent_transactions:
else: