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
Server Side Programming Articles - Page 856 of 2650
302 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
477 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
107 Views
To check if the Pandas Index only consists of booleans, use the index.is_boolean() method in Pandas. At first, import the required libraries -import pandas as pdCreating Pandas indexindex = pd.Index([True, True, False, False, True, True, True]) Display the Pandas index −print("Pandas Index...", index)Check whether index values have only booleans −print("Index values only consists of booleans?", index.is_boolean()) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index([True, True, False, False, True, True, True]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements ... Read More
4K+ Views
To insert a new index value at the first index from the last, use the index.insert() method. Set the last index value -1 and the value to be inserted as parameters.At first, import the required libraries -import pandas as pdCreating the Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck']) Display the index −print("Pandas Index...", index)Insert a new value at the first index from the last using the insert() method. The first parameter in the insert() is the location where the new index value is placed. The -1 here means the new index value gets inserted at the first index ... Read More
5K+ Views
Convert Timestamp to another time zone, use the timestamp.tz_convert(). Set the time zone as the parameter. At first, import the required libraries −import pandas as pdCreate the timestamp object in Pandas. We have also set the timezonetimestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern') Convert timezone of timestamptimestamp.tz_convert('Australia/Brisbane'))ExampleFollowing is the code import pandas as pd # set the timestamp object in Pandas # we have also set the timezone timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern') # display the Timestamp print("Timestamp...", timestamp) # convert timezone print("Convert the Timestamp timezone...", timestamp.tz_convert('Australia/Brisbane'))OutputThis will produce the following code Timestamp... 2021-10-14 15:12:34.261811624-04:00 Convert the Timestamp timezone... ... Read More
276 Views
To return proleptic Gregorian ordinal, use the timestamp.toordinal() method. At first, import the required libraries −import pandas as pdCreate the timestamp object in Pandastimestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33) Return proleptic Gregorian ordinal. Example: January 1 of year 1 is day 1timestamp.toordinal()ExampleFollowing is the code import pandas as pd # set the timestamp object in Pandas timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33) # display the Timestamp print("Timestamp...", timestamp) # Return proleptic Gregorian ordinal. # Example: January 1 of year 1 is day 1. print("Gregorian ordinal...", timestamp.toordinal())OutputThis will produce the following code Timestamp... 2021-09-18 11:50:20.000033 Gregorian ordinal... 738051
2K+ Views
To insert a new index value at a specific position, use the index.insert() method in Pandas. At first, import the required libraries -import pandas as pdCreating the Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck']) Display the index −print("Pandas Index...", index)Insert a new value at a specific position using the insert() method. The first parameter in the insert() is the location where the new index value is placed. The 2 here means the new index value gets inserted at index 2 i.e. position 3. The second parameter is the new index value to be inserted.print("After inserting a new index ... Read More
8K+ Views
Get the current date and time from Timestamp object, use the timestamp.today() method.At first, import the required libraries −import pandas as pd import datetimeCreate the timestamp in Pandastimestamp = pd.Timestamp(datetime.datetime(2021, 10, 10)) Display the Timestampprint("Timestamp: ", timestamp)Getting the current date and timeres = timestamp.today() ExampleFollowing is the code import pandas as pd import datetime # set the timestamp in Pandas timestamp = pd.Timestamp(datetime.datetime(2021, 10, 10)) # display the Timestamp print("Timestamp: ", timestamp) # display the day from given timestamp print("Day Name:", timestamp.day_name()) # getting the current date and time res = timestamp.today() # display the ... Read More