Search code examples
pythonpython-2.7pandaspandas-datareader

Pandas find max value from series of mixed data


Am using Pandas df and in dataframe i was able to extract to series named 'xy' that look like this:

    INVOICE
2014-08-14 00:00:00
4557
Printing
nan 
Item    AMOUNT
nan
1   9.6 
0
0
0
9.6
2
11.6
nan 
nan
nan

what i need to find is maximum value which is usually located towards the end of 'xy' pandas series i tried to convert it to string i get into problems as some of the series are string not int or float i need a good way as i am writing this script for several different files


Solution

  • try to use pd.to_numeric

    pd.to_numeric(xy, 'coerce').max()
    
    4557.0
    

    to get the last float number

    s = pd.to_numeric(xy, 'coerce')
    s.loc[s.last_valid_index()]