PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 13, 2022

[FIXED] How can I use iloc to extract rows of a dataframe to create a separate dataframe?

 May 13, 2022     append, dataframe, for-loop, pandas, python     No comments   

Issue

I have a dataframe from which I would like to extract specific rows and create a separate dataframe consisting of those extracted rows.

The following is an example:

df =

Col1 Col2 Col3
0 red blue yellow
1 monago orange apple
2 five six seven

I have the row indices in an array called row_ind with values (0,2):

for i in range(len(df))
    a = row_ind[i]
    b = df.iloc[a]

How can I use this to create the data set that I want?


Solution

foo = []

for i in range(len(df))
    a = row_ind[i]
    foo.append(a)

newdf = df.iloc[foo]


Answered By - Igor Rivin
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing