10 examples of 'pandas to_datetime timezone' in Python

Every line of 'pandas to_datetime timezone' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
274def get_tz(df):
275 index = df.index
276 try:
277 tz = index.tz
278 except AttributeError:
279 tz = None
280 return tz
148def localize_datetime(x):
149 if pd.isnull(x) or isinstance(x, pd.tslib.NaTType):
150 return None
151 utz_tz = pytz.timezone('UTC')
152 local_tz = pytz.timezone(utc_to_tz)
153 d = utz_tz.localize(x)
154 d = d.astimezone(local_tz)
155 # make naive.
156 return d.replace(tzinfo=None)
60def set_datetime_timezone_utc(dt):
61 return pytz.utc.localize(dt)
519def get_and_fill_timezone(df):
520 '''
521 this is new to deal with healthkit data
522 requires that a data frame that contains payload and HKTimeZone is passed
523 '''
524 df = get_healthkit_timezone(df)
525
526 df["timezone"].fillna(method='ffill', inplace=True)
527 df["timezone"].fillna(method='bfill', inplace=True)
528
529 return df["timezone"]
10def convert_timezone(datetime):
11 """Converts datetime to timezone aware datetime.
12
13 Retrieving timezone:
14
15 - get `timezone` from .ini settings
16 - default to system timezone
17
18 """
19 if datetime is None:
20 return None
21
22 timezone = get_current_registry().settings.get('timezone', None)
23 if not timezone:
24 timezone = time.tzname[0]
25 return pytz.timezone(timezone).localize(datetime)
196def rebase_to_timezone(datetime):
197 """Convert a datetime object to the blog timezone."""
198 if datetime.tzinfo is None:
199 datetime = datetime.replace(tzinfo=UTC)
200 tzinfo = get_timezone()
201 return tzinfo.normalize(datetime.astimezone(tzinfo))
332def _convert(self, dt): # type: (datetime) -> datetime
333 if dt.tzinfo is not self:
334 return dt.astimezone(self)
335
336 return dt
140def tz_strip(self, data_frame):
141 """
142 tz_strip - Converts a tz-aware DatetimeIndex into a tz-naive DatetimeIndex,
143 effectively baking the timezone into the internal representation.
144
145 Parameters
146 ----------
147 datetime_index : pandas.DatetimeIndex, tz-aware
148
149 Returns
150 -------
151 pandas.DatetimeIndex, tz-naive
152 """
153
154 # data_frame = tsc.convert_index_aware_to_UTC_time(data_frame)
155
156 datetime_index = data_frame.index
157
158 # Now convert to naive DatetimeIndex
159 data_frame.index = pandas.DatetimeIndex(datetime_index.values)
160
161 return None #(TODO fix as doesn't work)
553def to_datetime(self, dayfirst=False):
554 """
555 DEPRECATED: use :meth:`to_timestamp` instead.
556
557 Cast to DatetimeIndex.
558 """
559 warnings.warn("to_datetime is deprecated. Use self.to_timestamp(...)",
560 FutureWarning, stacklevel=2)
561 return self.to_timestamp()
90def localize(self, dt):
91 return datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute,
92 dt.second, dt.microsecond, tzinfo=self)

Related snippets