Skip to content
Advertisement

Appending new value to the dataframe

JavaScript

Above code prints same value twice i.e.

JavaScript

Why is it not appending NSEI at the end of the stocksList dataframe?

Full code:

JavaScript

Advertisement

Answer

how your code is flawed

Relying on the length of the index on a dataframe with a reworked index is not reliable. Here is a simple example demonstrating how it can fail.

input:

JavaScript
JavaScript

Pre-processing:

JavaScript

Attempt to append a row at the end using index length:

JavaScript

See what happended here? len(df.index) is 2, but 2 is an already existing row.

how to fix it

Use a reliable method to append a new row. Let’s start again from:

JavaScript
JavaScript

Or, aternatively:

JavaScript

but be careful of SettingWithCopyWarning

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement