'Is it possible to delete items from a list in a loop using pandas
I am trying to use a list in order to append to a pandas data frame. In the process of this, I want to append the values from the list to the dataframe and then delete the values in the list, where it is then meant to repeat in a loop.
However, what it does instead is register the last pair of inputs given, there are no error values it simply does not include the other values I put in. What am I doing wrong, and do I need to do something completely different. Thanks
n = int(input("\nhow big is the sample size?: "))
p = "q"
num = 0
Sample1 = []
z = 1
for q in range (0, n):
c = float(input(f"\tAdd the predictor# {z}: ")) #z is to count the number of values for the list
d = float(input(f"\tAdd the response# {z}: "))
if q > 0:
Sample1.append(c) # to append the values to the list
Sample1.append(d)
df.loc[len(df)] = Sample1 #to append to separate dataframe
Sample1.clear() #to remove values of list to begin loop again
z = z+1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
