The issue is part of a much larger and more complex code but I have narrowed down the minimum reproducible behavior to the following
df1 = pd.DataFrame({'cola':[1,2,3], 'colb':['a','b','c']})
selected = df1[df1['cola'] == 1]
tempDf = pd.DataFrame({'col1':[selected['cola']], 'col2': [10]})
my expected output is a two column df with the values of 1 and 10. What I am getting is a two column df where the first column is 0 1 Name: cola, dtype: int64 and the second column is 10. How can I edit this code to only get the column value and what is causing this behavior?
tempDf = pd.DataFrame({'col1':selected['cola'], 'col2': [10]})get rid of extra squared bracket.selected['cola']itself is 1D values which you are putting inside a list that makes it include the indices as well.