I'd like to create a new column whose value is dependent on another column containing datetime or time data. So when time is between [x] and [y], value of new column is Z where Z is an integer.
I know that df['newColumn'] = np.where(df['price']>=100, 'yes', 'no') creates a new column with yes and nos when the price is more than 100. I want to do something similar with my Panda data frame, specifying if time range between X and Y, add "1" to new column, elif time range between X2 and Y2, add "2" to column and so on.
I did see df.loc['2002-1-1 01:00:00':'2002-1-1 04:00:00'] as a means of selecting a time range but couldn't quite put the two together. Any ideas anyone? NW
Aucun commentaire:
Enregistrer un commentaire