0

Assume this is my dataframe looks like

DF:
    A  B  C
    1  10 10
    2  5  5
    3  12 12
    4   6 7   
    5  21 22

Actually i need the help of how can i get each rows as np arrays. In each iteration with iterrows() or itertuples(): like

[1,10,10]
[2,5,5]
etc...

I see the thread which all convert to np arrays from the dataframe only. So kindly suggest me how can we achieve this.

  • do `df.vallues` – Buckeye14Guy Jan 06 '20 at 21:22
  • With `df.values`? – Willem Van Onsem Jan 06 '20 at 21:22
  • With [`df.to_numpy()`](https://stackoverflow.com/a/54508052/4909087). – cs95 Jan 06 '20 at 21:23
  • Df.values will convert total df to np arrays right? With my understanding ? Sorry – Sriramgirish Jan 06 '20 at 21:24
  • `a, b, c, d, e = df.to_numpy()` will unpack each row into separate variables, not that that makes much sense. – cs95 Jan 06 '20 at 21:25
  • I need to iterate each rows and convert that row only to the np arrays – Sriramgirish Jan 06 '20 at 21:26
  • No, you don't need to iterate over each row. This sounds like an XY problem. It'd be great if you could explain the problem you're trying to solve instead of asking how to do something you _think_ is the solution to that problem. – cs95 Jan 06 '20 at 21:26
  • @cs95 actually I cannot say it will contain 5 rows only it may contain 100 rows also – Sriramgirish Jan 06 '20 at 21:27
  • @cs95 yeah sorry about that! I'm trying that I need to read the csv and I have around 205 columns and numerous rows in that! So I need to write values of the rows to the text file using np.savetxt method with formatting in the append mode and I need to append all the values from rows to the text file one by one.so that I need np arrays which contains all the values in each rows. – Sriramgirish Jan 06 '20 at 21:31
  • Please edit your question with this information, I'll be happy to reopen so others can answer. – cs95 Jan 06 '20 at 22:30

0 Answers0