set_datetime#
One of the functions you can use to check certain columns of your data is set_datetime()
.
This function aims to check that you have the following Darwin Core Vocabulary Terms:
eventDate
: the date of your observation
It can also (optionally) can check the following:
eventTime
: year of your observationyear
: year of your observationmonth
: year of your observationday
: year of your observation
>>> import corella
>>> import pandas as pd
>>> events = pd.read_csv('<YOUR-FILENAME>.csv')
eventDate
and automatically converting strings#
Since we can specify the column names, we can specify the eventDate
column to be 'date'
.
>>> corella.set_datetime(dataframe=events,
... eventDate='date')
Traceback (most recent call last):
File "/Users/buy003/Documents/GitHub/corella-python/docs/source/corella_user_guide/longitudinal_studies/events_workflow.py", line 75, in <module>
new_events = corella.set_datetime(dataframe=events,eventDate='date')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/buy003/anaconda3/envs/galaxias-dev/lib/python3.11/site-packages/corella/set_datetime.py", line 101, in set_datetime
raise ValueError("There are some errors in your data. They are as follows:\n\n{}".format('\n'.join(errors)))
ValueError: There are some errors in your data. They are as follows:
the eventDate column must be in datetime format.
We get an error here because set_datetime()
requires the eventDate
column to be in a datetime
format. This is to make sure the date is formatted correctly. Luckily, set_datetime()
has a few
arguments that will convert dates in strings to datetime
format.
string_to_datetime
: when this is set toTrue
, will convert any strings in theeventDate
column todatetime
objects.yearfirst
: when this is set toTrue
,corella
(andpandas
) assumes your date starts with the year.dayfirst
: when this is set toTrue
,corella
(andpandas
) assumes your date starts with the day.
Note when both yearfirst
and dayfirst
are set to False
, pandas
assumes month is first.
>>> corella.set_datetime(dataframe=events,
... eventDate='date',
... string_to_datetime=True,
... yearfirst=False,
... dayfirst=True)
type location eventDate name
0 siteVisit Cannonvale 2023-01-03 bird survey local park honeyeater lookout point
1 siteVisit Cannonvale 2023-01-17 bird survey local park honeyeater lookout point
2 siteVisit Cannonvale 2023-01-31 bird survey local park honeyeater lookout point
3 siteVisit Cannonvale 2023-02-14 bird survey local park honeyeater lookout point
4 siteVisit Cannonvale 2023-02-28 bird survey local park honeyeater lookout point
what does check_data
and suggest_workflow
say now?#
Note: each of the set_*
functions checks your data for compliance with the
Darwin core standard, but it’s always good to double-check your data.
Now, we can check that our data column do comply with the Darwin Core standard.
>>> corella.check_data(events=events)
Number of Errors Pass/Fail Column name
------------------ ----------- -------------
0 ✓ eventDate
══ Results ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Errors: 0 | Passes: 1
✗ Data does not meet minimum Darwin core requirements
Use corella.suggest_workflow()
However, since we don’t have all of the required columns, we can run suggest_workflow()
again to see how our data is doing this time round.
>>> corella.suggest_workflow(dataframe=events)
── Darwin Core terms ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
── All DwC terms ──
Matched 1 of 4 column names to DwC terms:
✓ Matched: eventDate
✗ Unmatched: name, type, location
── Minimum required DwC terms events ──
Type Matched term(s) Missing term(s)
--------------------- ----------------- -----------------
Identifier - eventID
Linking identifier - parentEventID
Type of Event - eventType
Name of Event - Event
How data was acquired - samplingProtocol
Date of Event eventDate -
── Suggested workflow ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
── Events ──
To make your events Darwin Core compliant, use the following workflow:
corella.set_events()
Other functions#
To learn more about how to use these functions, go to
Optional functions: