Change language

Python | Pandas Series.dt.day_name

|

Series.dt can be used to access series values ​​as datetimelike and return multiple properties. Series.dt.day_name() Pandas Series.dt.day_name() returns the names of the DateTimeIndex days with the specified language standard.

Syntax: Series.dt.day_name (* args, ** kwargs)

Parameter:
locale: Locale determining the language in which to return the day name. Default is English locale.

Returns: Index of day names.

Example # 1: Use Series.dt.day_name () to return the day names of the underlying datetime data in the given series object. Return the day names in English.

# import pandas as pd

import pandas as pd

 
# Create Series

sr = pd .Series ([ ’2012-12-31 08:45’ , ’2019-1-1 12:30’ , ’ 2008-02-2 10:30’ ,

’2010-1-1 09:25 ’ , ’ 2019-12-31 00:00’ ])

 
# Create an index a

idx = [ ’Day 1’ , ’ Day 2’ , ’Day 3’ , ’ Day 4’ , ’Day 5’ ]

 
# set index

sr.index = idx

 
# Convert base data to date and time

sr = pd.to_datetime (sr)

 
# Print series

print (sr)

Output:

We will now use Series.dt.day_name () to return the day names of each timestamp in a given series object.

# return the day name in English

result = sr.dt.day_name (locale = ’English’ )

 
# print result

print (result)

Output:  

As we can see from the output, Series.dt.day_name ( ) successfully returned day names in the specified language.

Example # 2: Use Series.dt.day_name () to return day names the underlying datetime data in this series object. Return day names in French.

# import pandas as pd

import pandas as pd

 
# Create Series

sr = pd .Series (pd.date_range ( ’2012-12-31 09:45’ , periods = 5 , freq = ’Q’ ,

  tz = ’Europe / Berlin’ ) )

 < br /> # Index creation

idx = [ ’Day 1’ , ’Day 2’ , ’ Day 3’ , ’Day 4’ , ’ Day 5’ ]

 
# set index

sr.index = idx

 
# Print series

print (sr)

Output:

We will now use Series.dt.day_name () to return the day names of each timestamp in this series object.

# return the day name in French

result = sr.dt.day_name (locale = ’French’ )

 
# print the result

print (result)

Output:

As we can see from the output, Series.dt.day_name () successfully returned the day names in the specified language yke.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method