“Wyciąg z pandów miesiąc od daty” Kod odpowiedzi

Wydaj rok z datetime pandy

df['date'] = pd.to_datetime(df['date'],format='%Y%m%d')
df['year'] = pd.DatetimeIndex(df['date']).year
df['month'] = pd.DatetimeIndex(df['date']).month
The Frenchy

wyodrębnić tylko miesiąc z kolumny daty w pandy

df['month_year'] = df['date_column'].dt.to_period('M')
Exuberant Eland

Wyciąg z pandów miesiąc od daty

#if the date format comes in datetime, we can also extract the day/month/year using the to_period function
#where 'D', 'M', 'Y' are inputs
df['month_year'] = pd.to_datetime(df['birth_date']).dt.to_period('M')
df.head()
Difficult Dragonfly

Odpowiedzi podobne do “Wyciąg z pandów miesiąc od daty”

Pytania podobne do “Wyciąg z pandów miesiąc od daty”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu