In this article, we will learn how to get the rows from a dataframe as a list, without using the functions like ilic[]. There are multiple ways to do get the rows as a list from given dataframe. Let’s see them will the help of examples.
# importing pandas as pd import pandas as pd # Create the dataframe df = pd.DataFrame({'Date':['10/2/2011', '11/2/2011', '12/2/2011', '13/2/11'], 'Event':['Music', 'Poetry', 'Theatre', 'Comedy'], 'Cost':[10000, 5000, 15000, 2000]}) # using interrors() method # Create an empty list Row_list =[] # Iterate over each row for index, rows in df.iterrows(): # Create list for the current row my_list =[rows.Date, rows.Event, rows.Cost] # append the list to the final list Row_list.append(my_list) # Print the list print(Row_list) |
chevron_right
filter_none
Output:
[['10/2/2011', 'Music', 10000], ['11/2/2011', 'Poetry', 5000],
['12/2/2011', 'Theatre', 15000], ['13/2/11', 'Comedy', 2000]]
# Print the first 2 elements print(Row_list[:2]) |
chevron_right
filter_none
Output:
[['10/2/2011', 'Music', 10000], ['11/2/2011', 'Poetry', 5000]]
Recommended Posts:
- Select first or last N rows in a Dataframe using head() and tail() method in Python-Pandas
- Select any row from a Dataframe using iloc[] and iat[] in Pandas
- How to Select Rows from Pandas DataFrame?
- Select row with maximum and minimum value in Pandas dataframe
- How to select multiple columns in a pandas dataframe
- How to randomly select rows from Pandas DataFrame
- Select Rows & Columns by Name or Index in Pandas DataFrame using [ ], loc & iloc
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Python | Pandas Series.select()
- Python | Pandas dataframe.cov()
- Python | Pandas DataFrame.abs()
- Python | Pandas DataFrame.where()
- Python | Pandas DataFrame.ix[ ]
- Python | Pandas dataframe.add()
- Python | Pandas dataframe.eq()
- Python | Pandas dataframe.ne()
- Python | Pandas Dataframe.iat[ ]
- Python | Pandas DataFrame.loc[]
- Python | Pandas dataframe.mul()
- Python | Pandas Dataframe.at[ ]
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

