I want to import a python file called feature.py and call the functions in it, so I did the 'from feature import *'.
from feature import *
In the feature.py, I import pandas as pd and define the functions that I would like to call in the main python file.
import pandas as pd
# time features
def add_time_features(df):
df["date"] = pd.to_datetime(data.Timestamp, unit='s').dt.date
df["month"] = pd.to_datetime(data.Timestamp, unit='s').dt.month
df["weekday"] = pd.to_datetime(data.Timestamp, unit='s').dt.weekday_name
df["hour"] = pd.to_datetime(data.Timestamp, unit='s').dt.hour
However, when I run the main python program and call the function I got the error message said pd is not defined.
I thought I did define pd by using "import pandas as pd" in both main file and the feature.py. Bu it does not work. So what is the correct method to do this?