Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get the first element of a column using pandas

I have a csv file, which has couple of columns. The one I’m interested is ‘Date’ column and more specifically I’m interested by the first row of that column, the first date that appears.

So i have a file that i read as a csv using pandas:

FILE = pd.read_csv(FILENAME)
# doesnt work
last_scraped_date = FILE['Date'][0]

test_last_date = FILE.iloc[1]['Date']

the code above just prints nan. However if i directly print FILE['Date'] it starts printing me the whole column.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

All i want is to print the first row of that ‘Date’ column.

>Solution :

You had the right idea to use iloc function. You can do it like this instead:

FILE['Date'].iloc[0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading