1

PFA the code:

def Expiry_Time(x):
    x.Date=pd.to_datetime(x.Date)
    x.Expiry=pd.to_datetime(x.Expiry)
    options['Expiry_Time']=(x.Expiry - x.Date).dt.days
    return x

options=Expiry_Time(options)
options.head()

This calculates time to expiry for each row in the dataframe.

My doubt is as follows:

When I use

options.Expiry_Time=(x.Expiry - x.Date).dt.days

The column 'Expiry_Time is not added to the df as shown and a warning is given as shown:

Column Not Added

. But when I use:

options['Expiry_Time']=(x.Expiry - x.Date).dt.days

I get the required column as shown:

Column added

As shown in the warning message I went to the url which redirected me to:

Indexing In pandas

This page states that:

The Python and NumPy indexing operators [] and attribute operator . provide quick and easy access to pandas data structures across a wide range of use cases. This makes interactive work intuitive, as there’s little new to learn if you already know how to deal with Python dictionaries and NumPy arrays. However, since the type of the data to be accessed isn’t known in advance, directly using standard operators has some optimization limits. For production code, we recommended that you take advantage of the optimized pandas data access methods exposed in this chapter.

It states that as the type of data to be accessed isn’t known in advance, directly using standard operators has some optimization limits. What limits can it introduce?

For production code, we recommended that you take advantage of the optimized pandas data access methods exposed in this chapter. Why?

Huzefa Sadikot
  • 561
  • 1
  • 7
  • 22

0 Answers0