wrangle_in_py.extracting_ymd_hms ================================ .. py:module:: wrangle_in_py.extracting_ymd_hms Functions --------- .. autoapisummary:: wrangle_in_py.extracting_ymd_hms.extracting_ymd wrangle_in_py.extracting_ymd_hms.extracting_hms Module Contents --------------- .. py:function:: extracting_ymd(df, column) Returns a copy of the input DataFrame with three new columns: year, month, and day, extracted from the specified datetime column. :param df: The DataFrame containing the datetime column. :type df: pandas.DataFrame :param column: The name of the datetime column to extract from. :type column: str :raises KeyError :: If the input column is not a column in df. :raises TypeError :: If the input column is not of datetime type. :returns: A copy of the input DataFrame with added columns: '_year', '_month', '_day'. :rtype: pandas.DataFrame .. rubric:: 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 .. py:function:: extracting_hms(df, column) Returns a copy of the input DataFrame with three new columns: hour, minute, and second, extracted from the specified datetime column. :param df: The DataFrame containing the datetime column. :type df: pd.DataFrame :param column: The name of the datetime column to extract from. :type column: str :raises KeyError :: If the input column is not a column in df. :raises TypeError :: If the input column is not of datetime type. :returns: A copy of the input DataFrame with added columns: '_hour', '_minute', '_second'. :rtype: pd.DataFrame .. rubric:: 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