wrangle_in_py.extracting_ymd_hms
Functions
|
Returns a copy of the input DataFrame with three new columns: year, month, and day, |
|
Returns a copy of the input DataFrame with three new columns: hour, minute, and second, |
Module Contents
- wrangle_in_py.extracting_ymd_hms.extracting_ymd(df, column)[source]
Returns a copy of the input DataFrame with three new columns: year, month, and day, extracted from the specified datetime column.
- Parameters:
df (pandas.DataFrame) – The DataFrame containing the datetime column.
column (str) – The name of the datetime column to extract from.
- Raises:
KeyError : – If the input column is not a column in df.
TypeError : – If the input column is not of datetime type.
- Returns:
A copy of the input DataFrame with added columns: ‘<column>_year’, ‘<column>_month’, ‘<column>_day’.
- Return type:
pandas.DataFrame
Example
>>> df = pd.DataFrame({'timestamp': ['2024-01-07 12:30:45', '2023-12-25 08:15:30']}) >>> df['timestamp'] = pd.to_datetime(df['timestamp']) >>> extracting_ymd(df, 'timestamp') timestamp timestamp_year timestamp_month timestamp_day 0 2024-01-07 12:30:45 2024 1 7 1 2023-12-25 08:15:30 2023 12 25
- wrangle_in_py.extracting_ymd_hms.extracting_hms(df, column)[source]
Returns a copy of the input DataFrame with three new columns: hour, minute, and second, extracted from the specified datetime column.
- Parameters:
df (pd.DataFrame) – The DataFrame containing the datetime column.
column (str) – The name of the datetime column to extract from.
- Raises:
KeyError : – If the input column is not a column in df.
TypeError : – If the input column is not of datetime type.
- Returns:
A copy of the input DataFrame with added columns: ‘<column>_hour’, ‘<column>_minute’, ‘<column>_second’.
- Return type:
pd.DataFrame
Example
>>> df = pd.DataFrame({'timestamp': ['2024-01-07 12:30:45', '2023-12-25 08:15:30']}) >>> df['timestamp'] = pd.to_datetime(df['timestamp']) >>> extracting_hms(df, 'timestamp') timestamp timestamp_hour timestamp_minute timestamp_second 0 2024-01-07 12:30:45 12 30 45 1 2023-12-25 08:15:30 8 15 30