View Source DataframeTools.Date (Dataframe Tools v0.1.0)

Summary

Functions

Automagically try and convert a column in a dataframe to a date or datetime. It will check to see if the first 10 items in that column are dates, based on zero padding eg. 2021-01-01 yyyy-mm-dd and if so, convert to a date. If not, convert to a datetime.

Functions

Link to this function

convert_column_to_date(df, column_name)

View Source

Automagically try and convert a column in a dataframe to a date or datetime. It will check to see if the first 10 items in that column are dates, based on zero padding eg. 2021-01-01 yyyy-mm-dd and if so, convert to a date. If not, convert to a datetime.

TODO: look at converting numbers in a reasonable timestamp range to datetimes

Examples

iex> df = Explorer.DataFrame.new(%{
...>   dates: Explorer.Series.from_list(~w(2010-01-01 2020-02-01)),
...>   datetimes: Explorer.Series.from_list([1, nil])
...> })
iex> df2 = DataframeTools.Date.convert_column_to_date(df, :dates)
iex> Explorer.DataFrame.dtypes(df2)
%{"dates" => :date, "datetimes" => {:s, 64}}


iex> df = Explorer.DataFrame.new(%{
...>   dates: Explorer.Series.from_list(~w(2010-01-01 2020-02-01)),
...>   datetimes: Explorer.Series.from_list(["2024-04-25T13:05:41+10:00", "2024-04-01T13:05:41+10:00"])
...> })
iex> df3 = DataframeTools.Date.convert_column_to_date(df, :datetimes)
iex> Explorer.DataFrame.dtypes(df3)
%{"dates" => :string, "datetimes" => {:datetime, :microsecond}}