I have the user input a list of minutes and then a specific size. I then have a function that calculates the average price difference for every time that size shows up and this value is added to a list. Thus, I will have as many lists as the length of minutes. For example, if the user inputs 5,10; then I have 2 lists. I then try to add the list into a data frame, but am unable to as the lists are different in size and get an error that : ValueError: Length of values does not match length of index
This is the code I have for trying to insert the list into the dataframe (i is which element in the minutes list; i.e for 5,10 I have i=0 for 5 and i=1 for 10 done in a loop) list1 is a list, list2 is a dataframe:
list2.insert(i,i, list1)
export_csv = list2.to_csv(file2 ,index = None, header=False)
list1=[]
The error comes for this line of code: list2.insert(i,i, list1)
Here is an example:
List 1=[0.5,3.5,7.5]
then I want to insert it into the data frame: list2.insert(i,i, list1)
Then I want to empty the list.
Once it goes through the function the next list will be List1 is now= [7, 0.5, 8, 51.5, 2]
and I want to insert that into column 2, why I wrote list2.insert(i,i, list1)
Here is my full code if necessary:
#df is a data frame
#b is also a dataframe
#list2 is a dataframe
#list1 is a list
for i in range (0, len(df)):
size=df.iloc[i,0]
for i in range(0,len(numbers)-1):
for number in numbers:
#for i in range (0, len(numbers)-1):
print(number)
for filename in filenames:
b['diff']=abs(b['price']-b['orig_price'])
list1.extend((b['diff']))
print('size', size, list1)
list2[i+size+number]=list1
export_csv = list2.to_csv(file2 ,index = None, header=True)
list1=[]