1
df.shape (15,4)

I want to store 4th column of df within the loop in a list. What I'm trying is:

l=[]
n=1000 #No. of iterations
for i in range(0,n):
    #df expressions and results calcualtion equations
    l.append(df.iloc[:,2]) # This is storing values with index. I want to store then without indices while keeping inplace=True.

df_new = pd.DataFrame(np.array(l), columns = df.index)

I want l list to append only values from df column 3. Not series object of pandas.core.series module in each cell.

5
  • you want that 3rd column of a df stored as a list in another list over 1000 times? Commented Nov 9, 2020 at 11:58
  • Yes precisely, but without indices. This loop is taking a lot of time to run if iteration is increased further
    – Zee
    Commented Nov 9, 2020 at 14:20
  • this works - df.iloc[:,2].tolist ? Commented Nov 9, 2020 at 15:08
  • No. It's storing values as method objects in the list l.
    – Zee
    Commented Nov 10, 2020 at 6:09
  • 1
    Oh sorry, forgot the paranthesis.. I mean try df.iloc[:,2].tolist() Commented Nov 10, 2020 at 6:13

1 Answer 1

1

Use df.iloc[:,2]).tolist() inside append to get the desired result.

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.