2
$\begingroup$

enter image description hereI am new to Mathematica and I would like to select data from a database using dates as criteria. In this moment I am working on the ResourceData["New Orleans Slave Sales 1856-1861"] from the Wolfram Data Repository. I would like to select from the database only the rows in which the slaves were sold from 1858 till the end. I already tried with the function Select and DateRange

mydata = ResourceData["New Orleans Slave Sales 1856-1861"];    
Select[mydata,DateRange[DateObject[{1,1,1859}],DateObject[{1,1,1862}]]]

but apparently it does not work, or I am using it wrong. Could someone help me in debugging it or suggest me a better one?

$\endgroup$
  • $\begingroup$ the second argument of Select needs to evaluate to True or False; perhaps you could try Select[mydata,MemberQ[DateRange[DateObject[{1,1,1859}],DateObject[{1,1,1862}]],#]&] $\endgroup$ – user42582 Feb 24 '18 at 13:09
  • $\begingroup$ Unfortunately it seems to not make things better :/ $\endgroup$ – Carmine Ragone Feb 24 '18 at 13:16
  • $\begingroup$ how about dates=DateRange[DateObject[{1,1,1859}],DateObject[{1,1,1862}]]; mydata[Select[MemberQ[dates,#"SalesDate"]&]]? $\endgroup$ – user42582 Feb 24 '18 at 14:23
  • $\begingroup$ Nothing more than the white square.. $\endgroup$ – Carmine Ragone Feb 24 '18 at 14:28
5
$\begingroup$

Please try:

dates = DateRange[DateObject[{1859, 1, 1}], DateObject[{1862, 1, 1}]];
mydata[Select[MemberQ[dates, #"SalesDate"] &]]

The date format entered for WL is {yyyy,m,d} you were querying for a date that does not exists in the dataset

$\endgroup$
  • $\begingroup$ It does work! Thank you very much :) $\endgroup$ – Carmine Ragone Feb 24 '18 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.