Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas mean function returning NaN

I know this may be a newbie question, so please forgive me, but I have not found an answer which seems to make sense to/help me. I am importing data from a .csv file and need to slice out a particular part. I have done that and when I print the data frame and all values I need are present.

    df = pd.read_csv('C:/Users/Owner/Desktop/df.csv')
    dfr = df[44:58] #rows I need
    dfrc = dfr[['1','2','3','4','5']] #columns I need
    dfrc.mean(axis=1 skipna=True) #there are some NaNs present in the last index

What is returned

    44   NaN
    ...
    57   NaN
    dtype: float64

I am not sure why that is, but I need the numerical value for the mean of the index/row. I was hoping someone on the forum would be able to help. Thank you.

like image 906
Oatsbagoats Avatar asked Nov 01 '22 05:11

Oatsbagoats


1 Answers

Are you sure your data is really numeric (int or float)? Maybe you should try cast your columns before, and see if an error is raised.

dfrc = dfrc.astype(float)
like image 77
sweeeeeet Avatar answered Nov 15 '22 03:11

sweeeeeet