expectedparrot / edsl

Design, conduct and analyze results of AI-powered surveys and experiments. Simulate social science and market research with large numbers of AI agents and LLMs.
https://docs.expectedparrot.com
MIT License
168 stars 18 forks source link

Create method for transforming scenarios #861

Closed rbyh closed 2 weeks ago

rbyh commented 1 month ago

Say I want to import a CSV of survey responses but use the header row (of question texts) as scenarios in addition to / paired with scenarios for the responses. Existing method ScenarioList.from_csv() will automatically use the header row as the scenario keys, which is not desired (and also creates a formatting issue where keys are sentences).

It would be convenient to have a method / option for transforming scenarios that have been auto-generated in this way -- i.e., a way of specifying that (1) the original keys should become values for a new key and (2) the original values should be assigned a new key. The new keys would be identical across the values, by default, e.g., "question" and "response":

scenarios = ScenarioList.from_csv("filename.csv")

transformed_scenarios = []
for s in scenarios["scenarios"]:
    for question, response in scenario.items():
        transformed_scenarios.append({"question": question, "response": response})
rbyh commented 1 month ago

Need to think of how to handle potential additional columns that may or may not also be used, eg respondent ids.

rbyh commented 1 month ago

This may make the most sense to build as Conjure methods, however, there could be other types of scenarios that a user may want to construct in this way that are not survey responses.

johnjosephhorton commented 2 weeks ago

What I think we really want here is some optional parameters in from_ScenarioList that let you skip rows, re-name, come up with automatic valid indentifiers and so on. Right now, there's very little: https://github.com/expectedparrot/edsl/blob/88448ddbd6af402a605893e877e6dc8c57fec047/edsl/scenarios/ScenarioList.py#L693

@rbyh want to give some examples in a NB with CSVs you'd like to do something different with and maybe some proposed syntax?

rbyh commented 2 weeks ago

This is covered in new ScenarioList method unpivot.