Python - Iterate over a list of attributes
问题 I have a feature in my data set that is a pandas timestamp object. It has (among many others) the following attributes: year, hour, dayofweek, month. I can create new features based on these attributes using some brute force methods: df["year"] = df["timeStamp"].apply(lambda x : x.year) df["hour"] = df["timeStamp"].apply(lambda x : x.hour) . . . However, I want to iterate over a list: nomtimes = ["year", "hour", "month", "dayofweek"] for i in nomtimes: df[i] = df["timeStamp"].apply(lambda x :