0

I am trying to calculate basic statistics using pandas. I have precip values for a whole year from 1956. I created a "Date" column that has date for the entire year using pd.date_range. Then I calculated the max value for the year and the date of maximum value. The date of maximum value show "Timestamp('1956-06-19 00:00:00" as the output. How do I extract just the date. I do not need the timestamp or the 00:00:00 time

#Create Date Column
year = 1956
start_date = datetime.date(year,1,1)
end_date = datetime.date(year,12,31)
precip_file["Date"] = pd.date_range(start=start_date,end=end_date,freq="D")

#Yearly maximum value and date of maximum value
yearly_max = precip_file["Precip (mm)"].max(skipna=True)
max_index = precip_file["Precip (mm)"].idxmax()
yearly_max_date = precip_file.iat[max_index,2

Image of output dictionary I am trying to create

1 Answers1

0

May be a duplicate of this question, although I can't tell whether you are trying to convert one DateTime or a column of DateTimes.

bensonium
  • 71
  • 5
  • Thanks I just needed the .date argument so added the following line to extract date only. yearly_max_date = yearly_max_date.date() – Ankit Bista Sep 05 '20 at 06:06