I have an Excel file with three columns (Prefix, Feature, Values). All three are strings in Excel, but I need to turn the ‘Values’ entry from a string into a list when Prefix and Column equal the loop values.
Data looks like this:
| Prefix | Feature | Value |
|---|---|---|
| Prefix_1 | Feature1 | Value1,Value2,Value3 |
| Prefix_1 | Feature2 | Value4,Value5 |
| Prefix_1 | Feature3 | Value6,Value7,Value8,Value9 |
| Prefix_2 | Feature4 | Value10 |
It loops through all prefixes, then through all features, and I want to return the values in a list.
parametric_values = str(filtered_input.loc[filtered_input.Feature==column,'Value']).split(',')
filtered_input is a dataframe that is filtered to only the relevant prefixes and column is the value from the loop.
I would have expected parametric_values to be ['Value1','Value2','Value3'] for the first loop, but it returned as ['0 Value1', 'Value2', 'Value3\nName: Value', ' dtype: object']
I’m not sure why it returned a 0 to start with or the name and dtype object. What would I need to change with my code to get it to just return the values in the list?
>Solution :
Use this instead:
filtered_input.loc[filtered_input.Feature==column,'Value'].str.split(',').squeeze()