Reputation: 51
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.
Upvotes: 5
Views: 6572
Reputation: 1819
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)
Upvotes: 2