I have a dataset (tmp2) that is formatted as follows:
Company | Data_FY_19 | Data_FY_20 | Data_FY_21 |
---|---|---|---|
X | 341976.00 | 1.000 | 282872.00 |
Y | NaN | NaN | NaN |
Z | 4394.00 | 173.70 | 518478.00 |
What I want is a dataframe (tmp) that is formatted as:
Year | Company | Data |
---|---|---|
2019 | X | 341976.00 |
2020 | X | 1.000 |
2021 | X | 282872.00 |
2019 | Y | NaN |
2020 | Y | NaN |
2021 | Y | NaN |
2019 | Z | 4394.00 |
2020 | Z | 173.70 |
2021 | Z | 518478.00 |
I have created the dataframe with the years repeating from 2019-2021, but have trouble pasting in the data values and company names into the new dataframe. I have been trying to do it by looping through and pasting values into every third row like so:
tmp['Company'].iloc[::3] = tmp2['Company']
This however returns the following error:
A value is trying to be set on a copy of a slice from a DataFrame
What is the most efficient way to accomplich the above?