Home > Software design >  Python pandas series - how can I print only the value without the other information
Python pandas series - how can I print only the value without the other information

Time:09-28

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?

CodePudding user response:

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'

CodePudding user response:

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.

  • Related