Question: I need to calculate profit/loss percentage for closing prices over the given n days.
df is the data frame. Close Price is the closing price

```
def profit_loss(days):
    last = df[-1:]['Close Price']
    begin = df[-days:-(days-1)]['Close Price']
    return ((last-begin)/last)*100

```

the function is supposed to given the required percentage. If the days are given, the function takes the last day closing price and the last nth day closing price and calculate the profit/loss percentage. My output is giving me NaN as output

```
profit_loss(7)

```

The output is;

```
487   NaN
493   NaN
Name: Close Price, dtype: float64

```

The expected output is `-0.0102`.
The closing price data for the last 7 days is 

```
[970.20,981.75,979.95,980.50,980.45,975.35,979.10]

```

Answer: 
The main difference is stemming from the additional information that `encode_plus` is providing. If you read the documentation on the respective functions, then there is a slight difference for[`encode()`](https://huggingface.co/transformers/main_classes/tokenizer.html#transformers.PreTrainedTokenizer.encode):

> 
> Converts a string in a sequence of ids (integer), using the tokenizer and vocabulary.
>  Same as doing `self.convert_tokens_to_ids(self.tokenize(text))`.
> 
> 
> 

and the description of [`encode_plus()`](https://huggingface.co/transformers/main_classes/tokenizer.html#transformers.PreTrainedTokenizer.encode_plus):

> 
> Returns a dictionary containing the encoded sequence or sequence pair
>  **and additional information**: the mask for sequence classification and
>  the overflowing elements if a `max_length` is specified.
> 
> 
> 

Depending on your specified model and input sentence, the difference lies in the additionally encoded information, specifically the input mask. Since you are feeding in two sentences at a time, BERT (and likely other model variants), expect some form of masking, which allows the model to discern between the two sequences, see [here](https://huggingface.co/transformers/model_doc/bert.html#transformers.BertTokenizer.create_token_type_ids_from_sequences). Since `encode_plus` **is** providing this information, but `encode` **isn't**, you get different output results.
The tokenizer.encode\_plus function combines multiple steps for us:

1.- Split the sentence into tokens.
2.- Add the special [CLS] and [SEP] tokens.
3.- Map the tokens to their IDs.
4.- Pad or truncate all sentences to the same length.
5.- Create the attention masks which explicitly differentiate real tokens from [PAD] tokens.

Documentation is [here](https://huggingface.co/docs/transformers/main_classes/tokenizer?highlight=encode_plus#transformers.PreTrainedTokenizer.encode_plus)

```
# Tokenize all of the sentences and map the tokens to thier word IDs.
input_ids = []
attention_masks = []

# For every sentence...
for sent in sentences:
    # `encode_plus` will:
    #   (1) Tokenize the sentence.
    #   (2) Prepend the `[CLS]` token to the start.
    #   (3) Append the `[SEP]` token to the end.
    #   (4) Map tokens to their IDs.
    #   (5) Pad or truncate the sentence to `max_length`
    #   (6) Create attention masks for [PAD] tokens.
    encoded_dict = tokenizer.encode_plus(
                        sent,                      # Sentence to encode.
                        add_special_tokens = True, # Add '[CLS]' and '[SEP]'
                        max_length = 64,           # Pad & truncate all sentences.
                        pad_to_max_length = True,
                        return_attention_mask = True,   # Construct attn. masks.
                        return_tensors = 'pt',     # Return pytorch tensors.
                   )

```