Skip to content

Commit 4556f11

Browse files
committed
1 parent b284101 commit 4556f11

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pandas/_config/FirstDate.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pandas as pd
2+
3+
4+
import pandas as pd
5+
6+
# Create a pandas DataFrame with a date column
7+
df = pd.DataFrame({'date': ['4/03/2022', '5/03/2022', '6/03/2022'], 'patients': [16, 19, 11]})
8+
9+
# Convert the date column to a pandas `DatetimeIndex` object with the day first
10+
#df['year'] = pd.to_datetime(df['date'], yearFirst=False)
11+
df['year'] = pd.to_datetime(df['date'], dayfirst=True)
12+
13+
# Print the DataFrame
14+
print(df)
15+
16+
# Create a pandas DataFrame with a date column
17+
df = pd.DataFrame({'date': ['04/03/2004', '03/03/2005', '03/03/2007'], 'patients': [16, 19, 11]})
18+
19+
# Convert the date column to a pandas `DatetimeIndex` object with the day first
20+
#df['year'] = pd.to_datetime(df['date'], yearFirst=False)
21+
df['date'] = pd.to_datetime(df['date'], format='%d/%m/%Y').dt.strftime('%d-%m-%Y')
22+
23+
# Print the DataFrame
24+
print(df)
25+
26+
27+
28+

0 commit comments

Comments
 (0)