Generation

generate functionTue, 21 Mar 2023

There are 3 lists: water = [1,2,3,4,2,4,2,4,5,2,3,4,2,1,3,4,3,2,5,1] nutri = [1,2,4,6,5,6,7,5,4,5,6,7,4,3,5,5,6,5,4,3,5] mineral =[2,1,1,3,2,4,2,4,5,4,3,2,3,2,3,1,3,4,5,1,4] add them to df Pandas dataframe in the following format: index treatments value 0 0 water 25 1 1 water 30 2 2 water 28 3 3 nutri 36 4 4 nutri 29 5 0 nutri 45 6 1 mineral 55 7 2 mineral 29 8 3 mineral 56

import pandas as pd water = [1,2,3,4,2,4,2,4,5,2,3,4,2,1,3,4,3,2,5,1] nutri = [1,2,4,6,5,6,7,5,4,5,6,7,4,3,5,5,6,5,4,3,5] mineral =[2,1,1,3,2,4,2,4,5,4,3,2,3,2,3,1,3,4,5,1,4] treatments = pd.DataFrame({"water": water, "nutri": nutri, "mineral": mineral}, index=range(21)) treatments.reset_index().melt(id_vars=["index"], var_name="treatments", value_name="value")

Questions about programming?Chat with your personal AI assistant