Write a pandas function that parses MM/DD/YY date strings into datetime64 timestamps with an explicit format. It tests how the two-digit-year century pivot works, how to keep the index, name and dtype intact, and how to deal with strings that fail to parse.
Implement `parse_two_digit_year(s: pd.Series) -> pd.Series`. It converts US short-form date strings with two-digit years, such as `'03/15/21'`, into timestamps with `pd.to_datetime(s, format='%m/%d/%y')`. The C-standard century pivot applies: `'68'` maps to 2068 and `'69'` maps to 1969.
The function must:
- Pass an explicit `format='%m/%d/%y'` (no inference).
- Return dtype `datetime64[ns]`.
- Preserve the original `index` and `name`.
Example:
```python
s = pd.Series(['03/15/21', '12/01/99', '01/05/68', '07/04/69'])
parse_two_digit_year(s)
# 0 2021-03-15
# 1 1999-12-01
# 2 2068-01-05 # '68' -> 2068
# 3 1969-07-04 # '69' -> 1969
# dtype: datetime64[ns]
```
```hint Check what comes back
The parse itself is one call. Spend the rest of your effort on the result: the unit of its dtype, whether the index and name survived, and what a string that does not match the format does.
```
### What a Strong Answer Covers
- Parses with the explicit format string and says what inference could get wrong without it.
- States the two-digit-year pivot and checks it at the 68/69 boundary.
- Guarantees the `datetime64[ns]` dtype and keeps the input index and name.
- Covers missing values and strings that do not match the format.
### Follow-up Questions
- How would you force all two-digit years into the 1900s, or all into the 2000s, regardless of the default pivot?
- How would you handle malformed or out-of-range values in the Series?
- The column holds customer birth dates collected in 2024. How would you choose the century cutoff, and how would you check that choice against the data?
Overview: Write a pandas function that parses MM/DD/YY date strings into datetime64 timestamps with an explicit format. It tests how the two-digit-year century pivot works, how to keep the index, name and dtype intact, and how to deal with strings that fail to parse.
Implement parse_two_digit_year(s: pd.Series) -> pd.Series. It converts US short-form date strings with two-digit years, such as '03/15/21', into timestamps with pd.to_datetime(s, format='%m/%d/%y'). The C-standard century pivot applies: '68' maps to 2068 and '69' maps to 1969.
The function must:
Pass an explicit
format='%m/%d/%y'
(no inference).
Parses with the explicit format string and says what inference could get wrong without it.
States the two-digit-year pivot and checks it at the 68/69 boundary.
Guarantees the
datetime64[ns]
dtype and keeps the input index and name.
Covers missing values and strings that do not match the format.
Follow-up Questions Guidance
How would you force all two-digit years into the 1900s, or all into the 2000s, regardless of the default pivot?
How would you handle malformed or out-of-range values in the Series?
The column holds customer birth dates collected in 2024. How would you choose the century cutoff, and how would you check that choice against the data?