Skip to content
Advertisement

How to add multiple new dataframe columns based on an input number?

I require to create multiple new dataframe columns in one step. My approach was to ask the user “How many columns are required?” and based on the user input, that much new columns should be created at one go.

Following is my requirement in the form of code:

JavaScript

so to elaborate, instead of using insert function to create a column one by one, I want 4 columns with naming and values as NaN to be created when the user gives input as 4 something like this:

JavaScript

Then, based on value of prompt, new columns should be created.

Please let me know if this can be done or any other method to create columns automatically.

Advertisement

Answer

You can use the assign command –

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