set a column to pandas datetime with strf formatiing in python

You can set a column to Pandas datetime with strftime formatting using the pd.to_datetime() method and passing the format parameter with your desired strftime format.

main.py
        Example:

        ```python
        import pandas as pd

        # sample data
        data = {'date':['20211231', '20220101', '20220102'],
                'value':[1, 2, 3]}

        # create dataframe
        df = pd.DataFrame(data)

        # convert string to datetime with strftime formatting
        df['date'] = pd.to_datetime(df['date'], format='%Y%m%d')

        print(df)
        ```

        Output:
        ```
           date  value
        0 2021-12-31      1
        1 2022-01-01      2
        2 2022-01-02      3
        ```
550 chars
26 lines

gistlibby LogSnag