Server Side Programming Articles

Page 273 of 2109

Python - Check if the Pandas Index with some NaNs is a floating type

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 221 Views

To check if a Pandas Index with NaN values is a floating type, use the index.is_floating() method. This method returns True if the index contains floating-point numbers, even when NaN values are present. Syntax index.is_floating() This method returns a boolean value indicating whether the index is of floating-point type. Creating an Index with NaN Values First, let's create a Pandas index containing floating-point numbers and NaN values − import pandas as pd import numpy as np # Creating Pandas index with some NaNs index = pd.Index([5.7, 6.8, 10.5, np.nan, 17.8, ...

Read More

Python Pandas - Return a numpy timedelta64 array scalar view in nanoseconds

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 332 Views

To return a numpy timedelta64 array scalar view in nanoseconds, use the timedelta.asm8 property in Pandas. This property provides a direct numpy representation of the timedelta object. At first, import the required libraries − import pandas as pd Understanding Timedelta and asm8 The asm8 property returns a numpy.timedelta64 scalar, which represents time duration in nanoseconds internally. This is useful when you need to work with the underlying numpy representation. Example Following is the code − import pandas as pd # TimeDeltas is Python's standard datetime library uses a different ...

Read More

Python Pandas - Check if the Pandas Index holds Interval objects

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 278 Views

To check if a Pandas Index holds Interval objects, use the is_interval() method. This method returns True if the index contains interval objects, False otherwise. What are Interval Objects? Pandas Interval objects represent bounded intervals between two values. They are useful for categorizing continuous data or representing ranges. import pandas as pd # Create individual Interval objects interval1 = pd.Interval(10, 30) interval2 = pd.Interval(30, 50) print("Interval1:", interval1) print("Interval2:", interval2) Interval1: (10, 30] Interval2: (30, 50] Creating an IntervalIndex You can create a Pandas Index from Interval objects, which ...

Read More

Python - Get the weekday from Timestamp object in Pandas

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 4K+ Views

To get the weekday from a Timestamp object in Pandas, use the timestamp.weekday() method. This returns an integer where Monday = 0, Tuesday = 1, ..., Sunday = 6. Syntax timestamp.weekday() Basic Example Let's create a Timestamp and get its weekday ? import pandas as pd import datetime # Create a Timestamp object timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12)) # Display the Timestamp print("Timestamp:", timestamp) # Get the weekday (0=Monday, 1=Tuesday, ..., 6=Sunday) weekday = timestamp.weekday() print("Weekday number:", weekday) print("This is a Wednesday (2)") Timestamp: 2021-05-12 00:00:00 ...

Read More

Python Pandas - Get the UTC Offset Time

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

To get the UTC offset time in Pandas, use the timestamp.utcoffset() method. The UTC offset represents the time difference between a timezone and Coordinated Universal Time (UTC). What is UTC Offset? UTC offset shows how many hours a timezone is ahead or behind UTC. For example, EST is UTC-5, while IST is UTC+5:30. Basic Usage First, let's create a timestamp and get its UTC offset ? import pandas as pd # Creating a timestamp with UTC timezone timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC') print("Timestamp:", timestamp) # Get the UTC offset time offset = timestamp.utcoffset() ...

Read More

Python - Check if the Pandas Index holds categorical data

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

In Pandas, you can check if an Index contains categorical data using the is_categorical() method. This method returns True if the Index holds categorical data, otherwise False. Syntax index.is_categorical() Creating a Categorical Index First, let's create a Pandas Index with categorical data using the astype() method − import pandas as pd # Creating Pandas index with categorical data index = pd.Index(["Electronics", "Accessories", "Furniture"]).astype("category") # Display the Pandas index print("Pandas Index...") print(index) # Check the data type print("The dtype:") print(index.dtype) # Check whether index holds categorical data print("Does Index ...

Read More

Python Pandas - Construct a naive UTC datetime from a POSIX timestamp

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 535 Views

To construct a naive UTC datetime from a POSIX timestamp, use the pd.Timestamp.utcfromtimestamp() method. A POSIX timestamp represents the number of seconds since January 1, 1970, 00:00:00 UTC. What is a POSIX Timestamp? A POSIX timestamp (also called Unix timestamp) is the number of seconds that have elapsed since the Unix epoch (January 1, 1970, 00:00:00 UTC). It's a standard way to represent time across different systems. Basic Syntax pd.Timestamp.utcfromtimestamp(posix_timestamp) Example Let's create a Pandas timestamp and use it to construct a naive UTC datetime from a POSIX timestamp ? ...

Read More

Python - Check if the Pandas Index only consists of booleans

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 151 Views

To check if a Pandas Index only consists of boolean values, use the is_boolean() method. This method returns True if all index values are boolean (True or False), otherwise False. Syntax index.is_boolean() Return Value Returns True if the index contains only boolean values, False otherwise. Example with Boolean Index Let's create an index with only boolean values and check using is_boolean() ? import pandas as pd # Creating Pandas index with boolean values index = pd.Index([True, True, False, False, True, True, True]) # Display the Pandas index print("Pandas ...

Read More

Python Pandas - Insert a new index value at the first index from the last

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

To insert a new index value at the first index from the last, use the index.insert() method. The insert() method takes the position and value as parameters, where position -1 refers to the first index from the last. Creating a Pandas Index First, let's create a Pandas index with some sample values ? import pandas as pd # Creating the Pandas index index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck']) # Display the index print("Original Pandas Index:") print(index) Original Pandas Index: Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck'], dtype='object') Using insert() Method ...

Read More

Python Pandas - Convert Timestamp to another time zone

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 5K+ Views

Converting timestamps between time zones is essential when working with global data. Pandas provides the tz_convert() method to easily convert timezone-aware timestamps to different time zones. Import Required Libraries First, import the pandas library ? import pandas as pd Creating a Timezone-Aware Timestamp Create a timestamp object with an initial timezone. The timezone parameter accepts standard timezone names ? import pandas as pd # Create timestamp with US/Eastern timezone timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern') print("Original timestamp:", timestamp) Original timestamp: 2021-10-14 15:12:34.261811624-04:00 Converting to Another Time Zone ...

Read More
Showing 2721–2730 of 21,090 articles
« Prev 1 271 272 273 274 275 2109 Next »
Advertisements