Select any row from a Dataframe in Pandas | Python
Last Updated :
24 Oct, 2019
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.
import pandas as pd
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 ]})
Row_list = []
for index, rows in df.iterrows():
my_list = [rows.Date, rows.Event, rows.Cost]
Row_list.append(my_list)
print (Row_list)
|
Output:
[['10/2/2011', 'Music', 10000], ['11/2/2011', 'Poetry', 5000],
['12/2/2011', 'Theatre', 15000], ['13/2/11', 'Comedy', 2000]]
Output:
[['10/2/2011', 'Music', 10000], ['11/2/2011', 'Poetry', 5000]]
Share your thoughts in the comments
Please Login to comment...