python - Get values from a DataFrame in pandas -
i have dataframe 1 row in pandas.
the row has index/name date.
i want retrieve date , value in 4th column.
i can value of 4th column in single row using
first_row = data.iloc[0] value = row[3]
but how can corresponding date in row?
i have tried first_row.index
wont work. if use data.index
datetimeindex 1 element wouldn't better code if retrieve index directly row?
you have 2 choices, if performing integer indexing df, using same integer index index return value.
if have selected specific row can access index value using .name
attribute.
example:
in [3]: import io import pandas pd t="""date,value 2014/01/05,1515 2014/02/05,15 2014/05/05,1""" df=pd.read_csv(io.stringio(t), parse_dates=[0], index_col=[0]) df out[3]: value date 2014-01-05 1515 2014-02-05 15 2014-05-05 1 in [7]: df.index[1] out[7]: timestamp('2014-02-05 00:00:00') in [16]: df.iloc[1].name out[16] timestamp('2014-02-05 00:00:00')
Comments
Post a Comment