I've found other posts that refer to creating a new dataframe using specific conditions from another (like ID = 27, etc.) but nothing that allows me to make a new dataframe from specific row numbers of another.

Here is what I have tried so far:

To add a single row to a new dataframe:


To add a list of rows to a new dataframe:

entries_to_move = [10, 20, 30]
for i in entries_to_move:

Neither method works, so help would be appreciated. The output for either code is just a __.

Thank you!


1 Answer 1


So, your question is to instantiate a new data frame df2 from another data frame df1, by simply selecting rows.

You can do this by indexing. What is great by pandas DataFrames is that you can index a DataFrame using a list of indices.

df2 = df1.iloc[[list of indices],:] 
  • $\begingroup$ Thank you! I forgot about the end : and kept getting an empty df2. $\endgroup$
    – zoomh3x
    Commented Jul 3, 2020 at 1:06
  • $\begingroup$ Thank you, the last ':' I missed and lost quite a good amount of time. $\endgroup$ Commented Jun 3, 2021 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.