Skip to content
Advertisement

How can I separate one row from a data set but repeat in each line some of the variables?

I have a dataset where each row contains information that needs to be separated and printed in different rows, but I need to keep the name of the company on each newly printed row:

example dataset These are the headers:

JavaScript

These are 2 rows of data:

JavaScript

I need to separate one line into as many as I need. Some companies might have a marketing budget but don’t have a finance budget or any other possible combination… So the output should look like this (also I need to add the department, which is not included as a column, it is only the title of the column where the info is taken)

JavaScript

Advertisement

Answer

Given a text file that looks like:

JavaScript

We can do:

JavaScript

Output:

JavaScript

Testing, and how I’d make the values numeric for future calculations:

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