I have a large Dataset
with a few columns that contain ambiguous date strings in a variety of formats. I am wanting to reformat these so they are all the same. When it comes to values that are ambiguous, I am willing to take Wolfram's best guess.
Consider the following:
data = Dataset[{<|"Item" -> "a", "Date" -> "June 12, 2017"|>, <|
"Item" -> "b", "Date" -> "5/12/2014"|>, <|"Item" -> "c",
"Date" -> "01 September 1980"|>, <|"Item" -> "d",
"Date" -> "2006-03-15"|>, <|"Item" -> "e", "Date" -> "8/9/2008"|>,
<|"Item" -> "f", "Date" -> "5-8-99"|>}]
I can use the following code to pull the values and get a best guess in cases of an ambiguous date while using Quiet
to suppress the errors.
Quiet[DateString[
DateObject[#], {"Day", "-", "MonthNameShort", "-", "Year"}] & /@
Normal[data[[All, "Date"]]]]
{"12-Jun-2017", "12-May-2014", "01-Sep-1980", "15-Mar-2006", "09-Aug-2008", "08-May-1999"}
However, when I attempt to run that function on the dataset column, the ambiguous data causes a failure and the results aren't computed.
cleandata =
data[All, {"Date" -> (Quiet[
DateString[
DateObject[#], {"Day", "-", "MonthNameShort", "-",
"Year"}] &])}]
Is there a way to force Mathematica to work through this Failure, or am I going to have to extract the data, run the function, then replace the column data?
This particular dataset has about 250K entries with about 10 columns that need this treatment.
For now, I am using the following with the replacement code being run for every column before reassembling but it seems terribly inefficient, especially when having to do this for multiple columns.
data = Normal@data;
data[[All, "Date"]] =
Quiet[DateString[
DateObject[#], {"Day", "-", "MonthNameShort", "-", "Year"}] & /@
data[[All, "Date"]]];
data = Dataset@data
Intepreter["Date"]
? Can't be (more) helpful right now, no Mathematica on this machine. $\endgroup$Interpreter
, but with a couple million entries, it was way too slow to be able to use. $\endgroup$