How to access elements from imported csv file with pandas in python? -


apologies basic question. new python , having problem codes. used pandas load in .csv file , having problem accessing particular elements.

 import pandas pd  dateytm = pd.read_csv('date.csv')  print(dateytm)  ##  result   #       date  # 0  20030131  # 1  20030228  # 2  20030331  # 3  20030430  # 4  20030530  #  # process finished exit code 0 

how can access first date? tried many difference ways wasn't able achieve want? many thanks.

you can use read_csv parameter parse_dates loc, see selection label:

import pandas pd import numpy np import io  temp=u"""date,no 20030131,1 20030228,3 20030331,5 20030430,6 20030530,3 """ #after testing replace io.stringio(temp) filename dateytm  = pd.read_csv(io.stringio(temp), parse_dates=['date']) print dateytm          date  no 0 2003-01-31   1 1 2003-02-28   3 2 2003-03-31   5 3 2003-04-30   6 4 2003-05-30   3  #df.loc[index, column]  print dateytm.loc[0, 'date'] 2003-01-31 00:00:00  print dateytm.loc[0, 'no'] 1 

but if need 1 value, better use at see fast scalar value getting , setting:

#df.at[index, column]  print dateytm.at[0, 'date'] 2003-01-31 00:00:00  print dateytm.at[0, 'no'] 1 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -