
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

150 Views
To check if the Pandas Index with some NaNs is a floating type, use the index.is_floating() method. At first, import the required libraries −import pandas as pd import numpy as npCreating Pandas index with some NaNs −index = pd.Index([5.7, 6.8, 10.5, np.nan, 17.8, 25.6, np.nan ,np.nan, 50.2]) Display the Pandas index −print("Pandas Index...", index)Check whether index values with some NaNs are floating type −print("Index values with some NaNs is a floating type?", index.is_floating())ExampleFollowing is the code −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, 25.6, ... Read More

274 Views
To return a numpy timedelta64 array scalar view in nanoseconds, use the timedelta.asm8 property in Pandas.At first, import the required libraries −import pandas as pdExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('10 min 20 s') # display the Timedelta print("Timedelta...", timedelta) # getting the timedelta64 in nanoseconds res = timedelta.asm8 # display the timedelta64 print("Timedelta64 array scalar view...", res)OutputThis will produce the following code Timedelta... 0 days 00:10:20 Timedelta64 array scalar view... 620000000000 nanoseconds

233 Views
To check if the Pandas Index holds Interval objects, use the index.is_interval() method in Pandas.At first, import the required libraries -import pandas as pdCreate Interval objects −interval1 = pd.Interval(10, 30) interval2 = pd.Interval(30, 50)Display the intervals −print("Interval1...", interval1) print("Interval2...", interval2)Creating Pandas index with Interval object1 and 2 −index = pd.Index([interval1, interval2]) Check whether index values has only interval objects −print("Does Index consists of Interval objects?", index.is_interval())ExampleFollowing is the code −import pandas as pd # create Interval objects interval1 = pd.Interval(10, 30) interval2 = pd.Interval(30, 50) # display the intervals print("Interval1...", interval1) print("Interval2...", interval2) # Creating Pandas index ... Read More

4K+ Views
To get the weekday from Timestamp object, use the timestamp.weekday() method. At first, import the required libraries −import pandas as pd import datetimeSet the timestamp in Pandas. Create a Timestamp objecttimestamp = pd.Timestamp(datetime.datetime(2021, 5, 12)) Get the weekday of the year. Weekday is represented by number Monday == 0, Tuesday == 1 … Sunday == 6timestamp.weekday()ExampleFollowing is the code import pandas as pd import datetime # set the timestamp in Pandas # create a Timestamp object timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12)) # display the Timestamp print("Timestamp...", timestamp) # getting the weekday of the year res = timestamp.weekday() ... Read More

2K+ Views
To get the UTC Offset Time, use the timestamp.utcoffset(). At first, import the required libraries −import pandas as pdCreating a timestamptimestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC') New timestamp with UTC day and timetimestamp.utcnow()Get the UTC offset timetimestamp.utcoffset() ExampleFollowing is the code import pandas as pd # creating a timestamp timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC') # display the Timestamp print("Timestamp...", timestamp) # new timestamp with UTC day and time print("UTC day and time...", timestamp.utcnow()) # Get the UTC offset time print("UTC offset time...", timestamp.utcoffset())OutputThis will produce the following code Timestamp... 2021-10-16 15:12:34.261811624+00:00 UTC day and time... 2021-10-03 07:56:44.685816+00:00 ... Read More

764 Views
To check if the Pandas Index is a floating type, use the index.is_floating() method in Pandas. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2]) Display the Pandas index −print("Pandas Index...", index)Check whether index values have only floats −print("Index values only consists of floats?", index.is_floating())ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number ... Read More

295 Views
To return a new Timestamp representing UTC day and time, use the timestamp.utcnow() method. At first, import the required libraries −import pandas as pdCreating a timestamptimestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC') New timestamp with UTC day and timetimestamp.utcnow()ExampleFollowing is the code import pandas as pd # creating a timestamp timestamp = pd.Timestamp('2021-10-16T15:12:34.261811624', tz='UTC') # display the Timestamp print("Timestamp...", timestamp) # new timestamp with UTC day and time print("UTC day and time...", timestamp.utcnow())OutputThis will produce the following code Timestamp... 2021-10-16 15:12:34.261811624+00:00 UTC day and time... 2021-10-03 07:56:08.901294+00:00Read More

1K+ Views
To check if the Pandas Index holds categorical data, use the index.is_categorical() method in Pandas. At first, import the required libraries -import pandas as pdCreating Pandas index with type set as category using the astype() method −index = pd.Index(["Electronics", "Accessories", "Furniture"]).astype("category") Display the Pandas index −print("Pandas Index...", index)Check whether index holds categorical data −print("Does Index holds categorical data?", index.is_categorical())ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index(["Electronics", "Accessories", "Furniture"]).astype("category") # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the ... Read More

468 Views
To construct a naive UTC datetime from a POSIX timestamp, use the timestamp.utcfromtimestamp() method. Pass the POSIX as an argument.At first, import the required libraries −import pandas as pdCreate a timestamptimestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') Constructing a naive UTC datetime from a POSIX timestamp. POSIX is passed as an argumenttimestamp.utcfromtimestamp(1631717502)ExampleFollowing is the code import pandas as pd # creating a timestamp timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') # display the Timestamp print("Timestamp...", timestamp) # constructing a naive UTC datetime from a POSIX timestamp # POSIX is passed as an argument print("Construct UTC Datetime...", timestamp.utcfromtimestamp(1631717502))OutputThis will produce the following code Timestamp... 2021-09-14 15:12:34.261811624 ... Read More

4K+ Views
To convert naive Timestamp to local time zone, use the timestamp.tz_locale(). Within that, set the timezone using the tz parameter.At first, import the required libraries −import pandas as pdCreating a naive timestamptimestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') Add the timezonetimestamp.tz_localize(tz='Australia/Brisbane')ExampleFollowing is the code import pandas as pd # creating a naive timestamp timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') # display the Timestamp print("Timestamp...", timestamp) # add a timezone print("Timestamp to local time zone...", timestamp.tz_localize(tz='Australia/Brisbane'))OutputThis will produce the following code Timestamp... 2021-09-14 15:12:34.261811624 Timestamp to local time zone... 2021-09-14 15:12:34.261811624+10:00Read More