SUM COLUMNS & ROWS IN A DATAFRAME | How to sum columns and rows in a Pandas DataFrame

Поделиться
HTML-код
  • Опубликовано: 13 янв 2025

Комментарии • 18

  • @ChartExplorers
    @ChartExplorers  3 года назад

    Hello Everyone! Thanks for clicking on this video. If you find it difficult to see please please check out this video here where I zoom in on the text ruclips.net/video/YEkqaJSZzNg/видео.html

  • @Zenoandturtle
    @Zenoandturtle Год назад

    Great video. I was after this particular topic.

  • @chrisbagshaw5676
    @chrisbagshaw5676 4 года назад +4

    Thanks, awesome video bro!

  • @brooklynjames4423
    @brooklynjames4423 4 года назад +1

    Very informative! Please make more videos like this.

  • @Diego_-
    @Diego_- 4 года назад +1

    thank you!!! simple !

  • @joegalbraith1585
    @joegalbraith1585 4 года назад

    Great video, thanks.

  • @kofiasante9477
    @kofiasante9477 3 года назад +1

    How do we sum some rows and not all the rows?

    • @ChartExplorers
      @ChartExplorers  3 года назад

      Hi Kofi,
      We can select which rows we want to sum using iloc. Here is an example
      df['sum_some_rows'] = df.iloc[0:3].sum(axis=1)
      Here we just past the index location of the rows that we want to sum to iloc. In the above example we are say get the sum in for rows 0, 1, &, 2 (up to but not including three).
      If you wanted to sum the last 5 rows we could use .iloc[-5:]
      or if we wanted to sum rows at index 2 through 6 we could use .iloc[2:7]

  • @lijithmohanan928
    @lijithmohanan928 4 года назад

    in the fist example, need to know how to add new row at the end and have a sum result

    • @ChartExplorers
      @ChartExplorers  4 года назад +1

      Is this what you are looking for? This will add the column sums as a new row to the end of the DataFrame.
      df.loc[len(df)] = df.sum(axis=0)

  • @harshitagupta5372
    @harshitagupta5372 3 месяца назад

    Wow

  • @brendensong8000
    @brendensong8000 4 года назад +1

    Great video. Thank you. However, videos are too small to see what you are coding.

    • @ChartExplorers
      @ChartExplorers  4 года назад

      Hi Brenden, thanks! I agree it is hard to see if especially if you are not on a computer. I have updated this video with larger text to improve visibility.
      ruclips.net/video/YEkqaJSZzNg/видео.html

  • @janats8727
    @janats8727 4 года назад

    it's not working for the data loaded from csv.

    • @ChartExplorers
      @ChartExplorers  4 года назад

      What error message are you getting?

    • @ChartExplorers
      @ChartExplorers  4 года назад

      A common error is *TypeError: can only concatenate str (not "int") to str* . This means that some of your data in the column (or row) that you are trying to sum contains both strings and integers/floats. If this is the case you can convert your column to all numeric values. This video provides a detailed explanation on how to do that ruclips.net/video/evKYySLSzyk/видео.html Once all your values are converted to numeric this TypeError should go away.

  • @ceritamenarikk
    @ceritamenarikk 3 года назад +1

    screen is too small, have to use microscope

    • @ChartExplorers
      @ChartExplorers  3 года назад +2

      Wow, I'm impressed you could get your screen under a microscope!! 😄 Being serious though, I agree, it is really small. I actually made this updated video that is easier to see ruclips.net/video/YEkqaJSZzNg/видео.html