Spaces:
Build error
Build error
Commit
·
ca879f8
1
Parent(s):
dcda405
Create utils/feature_engineering.py
Browse files- utils/feature_engineering.py +11 -0
utils/feature_engineering.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils/feature_engineering.py
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def feature_engineering(df):
|
| 6 |
+
df['hour_of_day'] = pd.to_datetime(df['timestamp']).dt.hour
|
| 7 |
+
df['day_of_week'] = pd.to_datetime(df['timestamp']).dt.dayofweek
|
| 8 |
+
df['amount_times_hour'] = df['amount'] * df['hour_of_day']
|
| 9 |
+
df['log_amount'] = df['amount'].apply(lambda x: 0 if x == 0 else np.log(x + 1))
|
| 10 |
+
df = df.drop(['timestamp', 'amount'], axis=1)
|
| 11 |
+
return df
|