Found 10476 Articles for Python

Python Pandas - Get the year from the PeriodIndex object

AmitDiwan
Updated on 21-Oct-2021 06:14:45

229 Views

To get the year from the PeriodIndex object, use the PeriodIndex.year property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. We have set the frequency using the "freq" parameter −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display PeriodIndex frequency −print("PeriodIndex frequency object...", periodIndex.freq)Display year from the PeriodIndex object −print("The year from the PeriodIndex object...", periodIndex.year) ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the ... Read More

Python Pandas - Get the day of the week from the PeriodIndex object

AmitDiwan
Updated on 21-Oct-2021 06:13:13

138 Views

To get the day of the week from the PeriodIndex object, use the PeriodIndex.weekday property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display day of the week from the PeriodIndex object. The day of the week with Monday=0, Tuesday=1 ... Sunday=6 −print("The day of week from the PeriodIndex object...", periodIndex.weekday)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an ... Read More

Python Pandas - Get the week of the period from the PeriodIndex object

AmitDiwan
Updated on 21-Oct-2021 06:12:05

162 Views

To get the week of the period from the PeriodIndex object, use the PeriodIndex.week property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object: −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display week from the PeriodIndex object −print("The week from the PeriodIndex object...", periodIndex.week)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the frequency using the "freq" parameter periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', ... Read More

Python Pandas - Get the seconds of the period from the PeriodIndex object

AmitDiwan
Updated on 21-Oct-2021 06:10:26

116 Views

To get the seconds of the period from the PeriodIndex object, use the PeriodIndex.second property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="S")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display seconds from the PeriodIndex object −print("The seconds from the PeriodIndex object...", periodIndex.second)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the ... Read More

Python Pandas - Display the quarter of the date from the PeriodIndex object

AmitDiwan
Updated on 21-Oct-2021 06:08:43

195 Views

To display the quarter of the date from the PeriodIndex object, use the PeriodIndex.quarter property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display the quarter of the date from the PeriodIndex object −print("The quarter of the date from the PeriodIndex object...", periodIndex.quarter)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods ... Read More

Python Pandas - Get the month number of the period from the PeriodIndex object

AmitDiwan
Updated on 21-Oct-2021 06:07:45

423 Views

To get the month number of the period from the PeriodIndex object, use the PeriodIndex.month property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")Display PeriodIndex frequency −print("PeriodIndex frequency object...", periodIndex.freq) Display month number from the PeriodIndex object. The month id displayed as January=1, February=2 ... December=12 −print("The month number from the PeriodIndex object...", periodIndex.month)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set ... Read More

Python Pandas - Get the minute of the period from the PeriodIndex object

AmitDiwan
Updated on 20-Oct-2021 11:41:24

138 Views

To get the minute of the period from the PeriodIndex object, use the PeriodIndex.minute property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time −periodIndex = pd.PeriodIndex(['2021-09-25 07:30:35', '2019-10-30 04:15:45', '2021-07-15 02:55:15', '2022-06-25 09:40:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display minute from the PeriodIndex object −print("The minute from the PeriodIndex object...", periodIndex.minute)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the ... Read More

Python Pandas - Indicate if the date from the PeriodIndex object belongs to a leap year

AmitDiwan
Updated on 20-Oct-2021 11:40:27

99 Views

To indicate if the date from the PeriodIndex object belongs to a leap year, use the periodIndex.is_leap_year property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object −periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Check whether the date is a leap year −print("Whether the date is a leap year?", periodIndex.is_leap_year)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the frequency using the "freq" parameter periodIndex = ... Read More

Python Pandas - Get the hour of the period from the PeriodIndex object

AmitDiwan
Updated on 20-Oct-2021 11:39:27

147 Views

To get the hour of the period from the PeriodIndex object, use the PeriodIndex.hour property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time. We have set the frequency using the "freq" parameter −periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2021-07-15 02:25:15', '2022-06-25 09:20:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display hour from the PeriodIndex object −print("The hour from the PeriodIndex object...", periodIndex.hour)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating ... Read More

Python Pandas - Return the frequency object as a string from the PeriodIndex object

AmitDiwan
Updated on 20-Oct-2021 11:38:26

198 Views

To return the frequency object as a string from the PeriodIndex object, use the PeriodIndex.freqstr property.At first, import the required libraries −import pandas as pdCreate a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time −periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2021-07-15 02:25:15', '2022-06-25 07:20:55'], freq="T")Display PeriodIndex object −print("PeriodIndex...", periodIndex) Display PeriodIndex frequency as string −print("PeriodIndex frequency object as a string...", periodIndex.freqstr)ExampleFollowing is the code −import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the ... Read More

Advertisements