-1

I need to print a string on the first multi-index in a date format.

enter image description here

enter image description here

Essentially, I need to delete all data on the first date. But finding out the cause of this error is also very important to me. Thank you very much in advance!

Community
  • 1
  • 1
KrDan Rod
  • 91
  • 6
  • 1
    [Stack Overflow Discourages Screenshots](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). It is likely, the question will be downvoted, for containing unnecessary screenshots. By using screenshots, you are discouraging anyone from assisting you. No one wants to retype your stuff, from a screenshot, and screenshots are often, not readable. – Trenton McKinney Oct 21 '19 at 18:10
  • `date_our_full.loc['2019-09-13']`, not `iloc`. – Quang Hoang Oct 21 '19 at 18:11
  • Possible duplicate of [How are iloc, ix and loc different?](https://stackoverflow.com/questions/31593201/how-are-iloc-ix-and-loc-different) – Trenton McKinney Oct 21 '19 at 18:12
  • @QuangHoang KeyError: '2019-09-13' – KrDan Rod Oct 21 '19 at 18:15
  • Also, I believe `dt.date` does not give you back pandas datetime series, so you can't slice by string. – Quang Hoang Oct 21 '19 at 18:16
  • @TrentonMcKinney I will take this into account in the future. – KrDan Rod Oct 21 '19 at 18:17
  • @QuangHoang Could you also tell me how I can derive averages from the Time Index? – KrDan Rod Oct 21 '19 at 18:19

1 Answers1

0

As commented dt.date returns datetime.date object, which is different from Pandas' datetime object. Use dt.floor('D') or dt.normalized() instead. For example, this would work:

df['Date'] = df.session_started.dt.normalize()
df['Time'] = df.session_started.dt.hour

df_hour = df.groupby(['Date','Time']).checkbooking.count()
df_hour.loc['2019-01-13']
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74