I have a csv file that has only the two following rows:
ID CODE DATE STARTDATE AVERAGE1 AGGREGATE MEDIAN1 MEDIAN2 AVERAGE2 AVERAGE3 POSITION
123 112 2016OCT25 2016OCT25 821 3 1021 4000 172 183 S8
124 111 2016OCT25 2016OCT25 834 3 1025 4210 173 185 ENG
The position column takes values from S1-S8 and T1-T8(16 in total).I would like to create a dataframe that looks like the following:
AVERAGE1 MEDIAN1 MEDIAN2 AVERAGE2 AVERAGE3 POSITION
S1
S2
S3
S4
S5
S6
S7
S8
T1
T2
T3
T4
T5
T6
T7
T8
Now the problem is if the 'POSITION' column in the csv file reads 'ENG' the same corresponding data in the column data has to be filled for all the positions in the dataframe, from S1-T8. If it reads any particular position , for example S8 in the second column above, the data from that column in the csv has to be filled to the corresponding POSITION in the dataframe. To make it more clear, the output should look like this:
AVERAGE1 MEDIAN1 MEDIAN2 AVERAGE2 AVERAGE3 POSITION
821 1021 4000 172 183 S1
821 1021 4000 172 183 S2
821 1021 4000 172 183 S3
821 1021 4000 172 183 S4
821 1021 4000 172 183 S5
821 1021 4000 172 183 S6
821 1021 4000 172 183 S7
834 1025 4210 173 185 S8
821 1021 4000 172 183 T1
821 1021 4000 172 183 T2
821 1021 4000 172 183 T3
821 1021 4000 172 183 T4
821 1021 4000 172 183 T5
821 1021 4000 172 183 T6
821 1021 4000 172 183 T7
821 1021 4000 172 183 T8
I have accomplished this by creating an empty dataframe and then filled the cells with df.iloc after reading the csv. Any method that is more efficient or pythonic will be much appreciated. Thanks in advance!