timezone_shift
timezone_shift ¤
TimezoneShift ¤
TimezoneShift(
dataframe: DataFrame, column_name: str = "systime"
)
Bases: Base
A class for shifting timestamps in a DataFrame to a different timezone, with methods to handle timezone localization and conversion.
shift_timezone
classmethod
¤
shift_timezone(
dataframe: DataFrame,
time_column: str,
input_timezone: str,
target_timezone: str,
) -> pd.DataFrame
Shifts timestamps in the specified column of a DataFrame from a given timezone to a target timezone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The DataFrame containing the data. |
required |
time_column
|
str
|
The name of the time column to convert. |
required |
input_timezone
|
str
|
The timezone of the input timestamps (e.g., 'UTC' or 'America/New_York'). |
required |
target_timezone
|
str
|
The target timezone to shift to (e.g., 'America/New_York'). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with timestamps converted to the target timezone. |
add_timezone_column
classmethod
¤
add_timezone_column(
dataframe: DataFrame,
time_column: str,
input_timezone: str,
target_timezone: str,
) -> pd.DataFrame
Creates a new column with timestamps converted from an input timezone to a target timezone, without altering the original column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The DataFrame containing the data. |
required |
time_column
|
str
|
The name of the time column to convert. |
required |
input_timezone
|
str
|
The timezone of the input timestamps. |
required |
target_timezone
|
str
|
The target timezone. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with an additional column for the shifted timezone. |
list_available_timezones
classmethod
¤
list_available_timezones() -> list
Returns a list of all available timezones.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of strings representing all available timezones. |
detect_timezone_awareness
classmethod
¤
detect_timezone_awareness(
dataframe: DataFrame, time_column: str
) -> bool
Detects if a time column in a DataFrame is timezone-aware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The DataFrame containing the data. |
required |
time_column
|
str
|
The name of the time column to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the column is timezone-aware, False otherwise. |
revert_to_original_timezone
classmethod
¤
revert_to_original_timezone(
dataframe: DataFrame,
time_column: str,
original_timezone: str,
) -> pd.DataFrame
Reverts a timezone-shifted time column back to the original timezone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The DataFrame containing the data. |
required |
time_column
|
str
|
The name of the time column to revert. |
required |
original_timezone
|
str
|
The original timezone to revert to. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with timestamps reverted to the original timezone. |
calculate_time_difference
classmethod
¤
calculate_time_difference(
dataframe: DataFrame, start_column: str, end_column: str
) -> pd.Series
Calculates the time difference between two timestamp columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The DataFrame containing the data. |
required |
start_column
|
str
|
The name of the start time column. |
required |
end_column
|
str
|
The name of the end time column. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
pd.Series: A Series with the time differences in seconds. |