- I can print 2 columns of a
pandas
data frame like this
- How do I format a row-by-row print?
- Here is my "ugly" solution followed by what I had expected to work
import pandas
def date_normalization(data: pandas.core.frame.DataFrame) -> None:
# EDIT: add completed code
# convert to desired date format
data[normalized] = pandas.to_datetime(
data[original],
errors="coerce",
).dt.strftime('%d/%m/%Y')
original = "start"
normalized = "normalized"
data = pandas.DataFrame({
original:
{
0: "AUG 26 2016",
1: "JAN-FEB 2021",
2: "2017-06-01 00:00:00"
}})
date_normalization(data)
# remove rows with invalid date
data = data[data[normalized].notnull()]
# arrggghh ... this is working, but ugly