1

I have a dataframe like the following:

df:

ts_dt                        Data                                                       
2019-01-01 01:51:31.540       5
2019-01-01 03:51:31.540      15
2019-01-02 03:51:31.540      15
2019-01-03 03:51:31.540      25
2019-01-03 05:51:31.540      25

I would like to get a list of the distinct days of ts_dt such as

days = [2019-01-01, 2019-01-02, 2019-01-03]
4
  • I'm hedging my bets here with the list of duplicates, but the 3rd one is specifically about columns with the pandas Timestamp type. There is also pandas.pydata.org/pandas-docs/stable/reference/api/… Commented Jan 7, 2020 at 12:55
  • So, if ts_dt has dtype Timestamp, then just use df.ts_dt.dt.date(). Then add .as_type(str) and .unique() and .tolist() as required. Commented Jan 7, 2020 at 12:55
  • df['ts_dt'].dt.date.drop_duplicates().tolist(), but first pd.to_datetime(df['ts_dt']) Commented Jan 7, 2020 at 12:57
  • Or: df['ts_dt'].dt.date.astype(str).unique() Commented Jan 7, 2020 at 12:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.