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

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

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

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

    Very clear. Great presentation.

  • @lawrencepaul6780
    @lawrencepaul6780 9 месяцев назад

    Excellent narration. Your videos are so precise. Not beating around the bush as many RUclipsrs do. I start following your videos recently and I it gives me great results. In the summing up of rows I encounter a problem of which I am not able to figure out. I tried to do the same example of yours and it is frustrating that I don't get the result. The code I have written is:
    df['sums'] = df.sum(axis=1).
    and I keep getting the error message: TypeError: unsupported operand type(s) for +: 'int' and 'str'
    Please... can you help me.

  • @zakriayasir2060
    @zakriayasir2060 2 года назад

    can you make a video on pandas real world projects? You described very well
    Or you have any course?

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

    Helpfull

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

    Hi Bradon. May I ask how do I sum x amount of vertical rows together? Let say I have a 1 hour data of walked miles in every row and I want manipulate the df to show walked miles for every 8 hours in one row, esentially combining 8, 1hour rows together.

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

      Hi Marcell,
      You can accomplish this with the following bit of code:
      N = 8
      df['col_1'].groupby(df.index // N).sum()
      N = represents the number of rows you want to sum
      df = your dataframe
      // divide with no remainder (round down)
      (df.index // N) - returns unique groups of the first 8 values, 2nd 8 values, 3rd 8 values,…
      Use groupby to sum the groups you are making with (df.index//N)
      This works because 0 // 8 = 0 through 7 //8 = 0 (this is your first group of 8 values), the second group of values 8//8 through 15//8 = 1, that is your second group of values

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

    Thanks! can you make this one as part of your set/series?

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

      Which series?

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

      @@ChartExplorers the playlist of which the original video was part of? honestly I only found this video because I was browsing the comments, and this one helped immensley. thanks !

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

      @@richarda1630 Oh I see, thanks for the suggestion! This video is in the same playlist, but it was hidden in the middle of the playlist. I've moved it so it show up just after the original video.

  • @sumithvarghese5753
    @sumithvarghese5753 2 года назад

    How can I sort on a summed up column, for example i grouped on (COL1).[Col2].Sum () , How can i sort on the newly created column and make a new dataframe.

  • @lucasschiffelers6927
    @lucasschiffelers6927 2 года назад

    What if you want to specify rows to sum?

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

    Thank you..

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

    how to sum a column of float numbers?

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

      It's the same for floats and integers. You will want to check the data type of the column and make sure it is not an object.
      df['col_name'].dtype
      If it is an object .sum() will not work and you will need to first convert the data type to float or int. You can learn more about converting data types in this video ruclips.net/video/evKYySLSzyk/видео.html
      Let me know if you run into any problems.

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

      @@ChartExplorers Thankyou!