Q: Anomaly using numPy datetime64 to work with dates in a pandas Dataframe column Cannot covert 'YYYY-MM' string to YYYY-MM datetime using datetime64 for data in pandas DataFrame.
np.datetime64 works to convert date string(s) of 'YYYY-MM' to datetime when stored in a scalar or array, but not when same data is accessed via a DateFrame.
What I want to do is convert a column dates (format: YYYY-MM) to datetime data (with or without adding another column).
csv file data:
month, volume
2019-01, 100
2019-02, 110

Sample Code:
import pandas as pd
import numpy as np

df=pd.read_csv (r'file location')
df["date"]=df["month"].apply(np.datetime64)

# Input (month): 2013-01
# Expected output (date): 2013-01
# Actual output (date): 2013-01-01

So, the datetime64 changes YYYY-MM to YYYY_MM-01
(Also, YYYY is converted to YYYY-01-01)

A: Perhaps you're looking for pd.Period:
In [11]: df.date.apply(pd.Period, freq='M')
Out[11]:
0   2019-01
1   2019-02
Name: date, dtype: object

Similarly, but without the apply:
In [12]: pd.to_datetime(df.date).dt.to_period(freq='M')
Out[12]:
0   2019-01
1   2019-02
Name: date, dtype: object

