I created a Dataframe with two columns and would like to append them based on the counting of values from other array.
cols = ['count_pos','count_neg']
df_count = pd.DataFrame(columns=cols)
I have the array y with values like y = [1,-1,-1,1,1,1,1,-1,-1]
Now i want to update for every change in value in y, count those occurrences and append to respective columns.
for i in range(1,10):
if y[i] == -1:
print(y[i])
if count_pos > 0:
df_count.loc['count_pos'].append = count_pos
count_pos = 0
count_neg = count_neg - 1
else:
if count_neg< 0:
print(count_neg)
df_count.loc['count_neg'].append = count_neg
count_neg = 0
count_pos = count_pos + 1
But I am not getting the result.Please let me know how can I append values to dataframe column.
My desired output is df_count
count_pos count_neg
1 -2
4 -2