<jupyter_start><jupyter_text>Pandas and DatetimesPandas helps ease the pain of timezones, even as it provides many useful tools for generating ```DateTimeIndex``` based time Series.<jupyter_code>import pandas as pd
from pandas import DataFrame, Series
import numpy as np
rng = pd.date_range('3/9/2012 9:30', periods=6, freq='D')
rng
type(rng)
rng2 = pd.date_range('3/9/2012 9:30', periods=6, freq='M')
rng2
ts = Series(np.random.randn(len(rng)), index=rng)
type(ts)
ts
ts.index.tz
rng.tz
ts_utc = ts.tz_localize('UTC')
ts_utc.index.tz
ts_utc
ts_pacific = ts_utc.tz_convert('US/Pacific')
ts_pacific
from IPython.display import YouTubeVideo
YouTubeVideo("k4EUTMPuvHo")
ts_eastern = ts_pacific.tz_convert('US/Eastern')
ts_eastern
ts_berlin = ts_pacific.tz_convert('Europe/Berlin')
ts_berlin<jupyter_output><empty_output><jupyter_text>Timestamp type (for individual datetimes)<jupyter_code>stamp = pd.Timestamp('2011-03-12 04:00')
stamp2 = pd.Timestamp('Wed May 23 11:35:54 2018') # will this work too?
type(stamp2)
stamp2_pac = stamp2.tz_localize('US/Pacific')
stamp2_pac
stamp2_pac.tz_convert('Europe/Moscow')
stamp2_pac.value # nanoseconds since the UNIX Epoch, Jan 1 1970
stamp2_pac.tz_convert('Europe/Moscow').value
stamp3 = pd.Timestamp('Wed May 23 11:35:54 1950') 
stamp3.value  # negative number because before the UNIX Epoch
ts
ts_sum = ts_eastern + ts_utc.tz_convert("Europe/Moscow")
ts_sum.index<jupyter_output><empty_output><jupyter_text>LAB CHALLENGEWhat time is it right now in:* Moscow* Berlin* Tokyo<jupyter_code>pd.Timestamp.now(tz='US/Pacific')  #  getting you started<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12096774193548387, 'fraction_numerical': 0.04590570719602978, 'mean_word_length': 7.146464646464646, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '195518', 'license': 'MIT', 'n_tokens_mistral': 688, 'n_tokens_neox': 617, 'n_words': 135, 'path': 'Dates3.ipynb', 'repo_name': '4dsolutions/Python5', 'size': '1612'}