Server Side Programming Articles

Page 245 of 2109

Python Pandas - Round a DateTimeIndex with frequency as multiples of a single unit

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 174 Views

To round a DateTimeIndex with frequency as multiples of a single unit, use the DateTimeIndex.round() method. The freq parameter accepts multipliers like '10T' for 10 minutes or '30S' for 30 seconds. Syntax DateTimeIndex.round(freq) Where freq is the frequency string with optional multiplier (e.g., '10T', '5H', '30S'). Creating a DateTimeIndex First, let's create a DateTimeIndex with precise timestamps ? import pandas as pd # DatetimeIndex with period 5 and frequency as H i.e. hours # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5, ...

Read More

Python Pandas - How to Round the DateTimeIndex with milliseconds frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To round the DateTimeIndex with milliseconds frequency, use the DateTimeIndex.round() method. For milliseconds frequency, use the freq parameter with value 'ms'. Creating a DateTimeIndex First, import pandas and create a DateTimeIndex with nanosecond precision ? import pandas as pd # Create DatetimeIndex with period 5 and frequency as 28 seconds # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='28s') print("Original DateTimeIndex:") print(datetimeindex) ...

Read More

Python Pandas - How to Round the DateTimeIndex with seconds frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To round the DateTimeIndex with seconds frequency, use the DateTimeIndex.round() method. For seconds frequency, use the freq parameter with value 'S'. Creating a DateTimeIndex First, let's create a DateTimeIndex with nanosecond precision ? import pandas as pd # Create DatetimeIndex with period 5 and frequency as 28 seconds # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='28s') print("Original DateTimeIndex...") print(datetimeindex) print("DateTimeIndex frequency:", datetimeindex.freq) ...

Read More

Python Pandas - Extract the day from the DateTimeIndex with specific time series frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 217 Views

To extract the day from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.day property. This property returns the day component from each datetime in the index as integers. Syntax DateTimeIndex.day This property returns an Int64Index containing the day values (1-31) for each datetime in the DateTimeIndex. Creating a DateTimeIndex First, let's create a DateTimeIndex with daily frequency ? import pandas as pd # Create DatetimeIndex with period 6 and frequency as D (daily) # Using Australia/Sydney timezone datetimeindex = pd.date_range('2021-10-20 02:35:55', periods=6, tz='Australia/Sydney', freq='D') print("DateTimeIndex...") print(datetimeindex) ...

Read More

Python Pandas - Extract month number from the DateTimeIndex with specific time series frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To extract month numbers from a DateTimeIndex with specific time series frequency, use the DateTimeIndex.month property. This returns integer values from 1 to 12 representing January through December. Creating a DateTimeIndex First, let's create a DateTimeIndex with monthly frequency ? import pandas as pd # DateTimeIndex with period 6 and frequency as M (month end) # Timezone is Australia/Sydney datetimeindex = pd.date_range('2021-09-24 02:35:55', periods=6, tz='Australia/Sydney', freq='M') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-09-30 02:35:55+10:00', '2021-10-31 02:35:55+11:00', '2021-11-30 02:35:55+11:00', '2021-12-31 ...

Read More

Python Pandas - Extract year from the DateTimeIndex with specific time series frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 2K+ Views

To extract years from a DateTimeIndex with specific time series frequency, use the DateTimeIndex.year property. This is particularly useful when working with time series data that has yearly frequency patterns. Syntax DateTimeIndex.year Creating DateTimeIndex with Yearly Frequency First, let's create a DateTimeIndex with yearly frequency and timezone ? import pandas as pd # DatetimeIndex with period 6 and frequency as Y i.e. years # timezone is Australia/Sydney datetimeindex = pd.date_range('2021-09-24 02:35:55', periods=6, tz='Australia/Sydney', freq='Y') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) DateTimeIndex... DatetimeIndex(['2021-12-31 02:35:55+11:00', '2022-12-31 02:35:55+11:00', ...

Read More

Python Pandas - Create a datetime with DateTimeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 5K+ Views

A DateTimeIndex is a pandas data structure for handling time series data. You can create a datetime series using pd.date_range() with customizable periods, frequency, and timezone settings. Basic DateTimeIndex Creation First, import the required library − import pandas as pd Creating a DateTimeIndex with date_range() Create a DateTimeIndex with 8 periods, monthly frequency, and Australia/Sydney timezone − import pandas as pd # Create DateTimeIndex with period 8 and frequency as M (months) # timezone is Australia/Sydney datetime = pd.date_range('2021-09-24 02:35:55', periods=8, tz='Australia/Sydney', freq='M') # Display the datetime print("DateTime...", datetime) ...

Read More

Python Pandas - Return vector of label values for requested level in a MultiIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 363 Views

To return vector of label values for requested level in a MultiIndex, use the get_level_values() method. This method accepts either a level number (integer) or level name (string) as an argument. Understanding MultiIndex A MultiIndex is a hierarchical index object that enables multi-dimensional indexing on pandas objects. Let's first create a MultiIndex: import pandas as pd # Create MultiIndex from arrays multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')], ...

Read More

Python Pandas - Get location and sliced index for requested label/ level in a MultiIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 234 Views

To get location and sliced index for requested label/level in a MultiIndex, use the get_loc_level() method in Pandas. This method returns both the location slice and the corresponding index values for the specified label. What is get_loc_level()? The get_loc_level() method returns a tuple containing: A slice object indicating the location range An Index object with the corresponding values from the specified level Creating a MultiIndex First, let's create a MultiIndex to demonstrate the method ? import pandas as pd # Create a MultiIndex from arrays multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')], ...

Read More

Python Pandas - Get location for a sequence of labels in a MultiIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 216 Views

To get location for a sequence of labels in a MultiIndex, use the MultiIndex.get_locs() method in Pandas. This method returns an array of integer positions where the specified label appears in the MultiIndex. Creating a MultiIndex First, let's create a MultiIndex using from_arrays() ? import pandas as pd # Create MultiIndex from two arrays multiIndex = pd.MultiIndex.from_arrays([list('pqrrst'), list('kytssp')]) # Display the MultiIndex print("The MultiIndex...") print(multiIndex) The MultiIndex... MultiIndex([('p', 'k'), ('q', 'y'), ...

Read More
Showing 2441–2450 of 21,090 articles
« Prev 1 243 244 245 246 247 2109 Next »
Advertisements