Monday, 30 December 2019

How to take a list and fill with values and put into a dataframe and filter in Python?

I have a list that has a file name and comes with multiple values for each file. I want to put the data into a data frame and filter.So there's 4 files and values.There should be 5 values each file that start with 'ab ..' or 'uo ..'.However some are missing values that are not there like in file one 'ab +1','co(0)','uo +2.5'.. where 'ab +1','co(0)' is missing 3 additional values. Iam looking to exclude those or fill in values with 0's.

values = [
    'file1','ab +5','co(0)','+107','+108','95%','ab +1','co(0)','uo +2.5','co(0)','+107','+107','90%','uo +2.5','co(0)','+107','+110','90%',
    'file2','ab +0.5','co(1)','ab +2.5','co(0)','+106','+102','95%','ab +2.5','co(0)','ab +8.0','co(1)','ab +2.5','co(0)','-106','+102','95%','uo +2.5','co(0)','+107','+107','90%',
    'file3','ab +3','co(0)','+107','+108','85%','co(0)','ab +4','co(0)','+107','+118','95%','uo +12.5','co(0)','+106','+107','90%',
    'file4','ab +3','co(0)','+107','+108','95%','uo +12.5','co(0)','+106','+107','90%'
]

wanted df results:
      0        1     2        3       4      5
0   file1   ab +1   co(0)   +107    +108    95%
1   file1   ab +1   co(0)   nan      nan    nan
2   file1   uo +2.5 co(0)   +107    +107    90%
3   file1   uo +2.5 co(0)   +107    +110    90%
4   file2   ab +0.5 co(1)    nan    nan     nan
5   file2   ab +2.5 co(0)   +106    +102    95%
6   file2   ab +2.5 co(0)   nan     nan     nan
7   file2   ab +8.0 co(1)   nan     nan     nan
8   file2   ab +2.5 co(0)   -106    +102    95%
9   file2   uo +2.5 co(0)   +107    +107    90%
10  file3   ab +3   co(0)   +107    +108    85%
11  file3   ab +4   co(0)   +107    +118    95%
12  file3   uo +12.5co(0)   +106    +107    90%
13  file4   ab +3   co(0)   +107    +108    95%
14  file4   uo +12.5co(0)   +106    +107    90%


from How to take a list and fill with values and put into a dataframe and filter in Python?

No comments:

Post a Comment