3

I have dataframe like this.

                                  E   F                                 
    ID    A     B       C     D   E   F
    0    0     ABC    AAA    BCD  1   -
    1    1     ABC    AAA    BCD  4   -  
    2    2     ABC    AAA    BCD  6   -

I print type of dataframe by print(type(df['E'])) it show output like this.

<class 'pandas.core.series.Series'>

I try to sum total value in column E but it show output like this

E146

How to sum data in dataframe column? The correct value should be 11 (1+4+6).

1
  • Use df['E'][-3] and sum. The sum function is not working properly on because of the single E character present in the column E of your dataframe. In that case it concatenates the values of the column which results in the output E146. Commented Aug 5, 2019 at 4:46

2 Answers 2

4

Use:

print(df['E'].iloc[1:].astype(int).sum())
Sign up to request clarification or add additional context in comments.

Comments

0

You may use pd.to_numeric with coerce to flip non-numeric value to NaN and sum will handle NaN by itself

pd.to_numeric(df['E'], errors='coerce').sum()

Out[45]: 11.0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.