Date time Flashcards
If you want to combine columns to have dates how do you do it?
pd.read_csv(url, parse_dates = [[0,1,2]]
When the index is a date, how do you select different dates?
df. loc(‘1996-08-01’)
df. index.month == 1
If you want to convert to datetime format how do you do it?
1) parse dates when importing
2) . pd.to_datetime
Alias for year end?
A, Y
Alias for year start?
AS, YS
Alias for weekly
W
Alias for month end?
M
Alias for month start?
MS
Alias for business mont end/
BM
Alias for quarter?
Q
Alias for business quarter end
BQ
How do you get isoformat dates?
datename.isoformat()
What is the method for converting a date into a string?
strftime
How do you get the month fully written out?
strftime(‘%B’)
How do you change bits of a datetime format?
dt.replace(minutes = 12)
How do you output datetime as strings?
variablenamehere.strftime(‘%Y’)
How do you parse strings as datetime?
datetime.strptime(‘string in here’, ‘%Y’)
What is the syntax for strftime?
variancename.strftime(‘%Y’)
What is the syntax for strptime?
datetime.strptime(‘string’,’%y’)
Which one has to have datetime in front?
datetime. strptime
variablename. strftime
How do you get a timezone stored?
timezone(timedelta(hours = -5))
When do you use replace and when do you use astimezone?
astimezone actually changes the stored time
replace just changes the offset
How do you change the timezone?
variable.astimezone(timezone)
How do you get timezones?
tz.gettz(‘Continent/City’)
What is the module for getting timezones
from dateutil import tz
How do you deal with daylight saving time?
Convert everything to UTC
How do you get the duration between times as a number rather than a timedelta?
total_seconds()