Python pandas series – how can I print only the value without the other information

Question:

I have a Python series that gives me the following:

df_1974.loc[[df_1974["Close*"].idxmin()]]['date_final']

type(df_1974.loc[[df_1974["Close*"].idxmin()]]['date_final'])

df_1974.loc[[df_1974["Close*"].idxmin()]]['date_final']
Out[8]: 
12099   1974-10-03
Name: date_final, dtype: datetime64[ns]

type(df_1974.loc[[df_1974["Close*"].idxmin()]]['date_final'])
Out[9]: pandas.core.series.Series

How can I print only the value 1974-10-03 without the other information?

Asked By: adrCoder

||

Answers:

You can convert this to_numpy() or to_list() or values and print the 0th element. e.g.,

>>> df_1974.loc[[df_1974["Close*"].idxmin()]]['date_final'].astype("str").to_list()[0]
>>> '1974-10-03'
Answered By: the_ordinary_guy

use df_1974.loc[[df_1974["Close*"].idxmin()]]['date_final'].values which returns an array from pandas series and select the first element if there is only one element in the data/series.

Answered By: maddyfrank
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.