Python Forum
Python Pandas for loop/while loop question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Pandas for loop/while loop question
#2
I think you are expecting k['num'] to return a list or closure. but it returns a DataFrame. The first time through the for loop the dataframe is [0 1] (what symbol does one use to denote a dataframe instead of a list or closure?) When you ask for k['num'][0] this works because the dataframe contains a zero. The second time through the loop k['num'] returns the dataframe [1 2]. This does not contain zero, so k['num'][0] raises a key error.
Reply


Messages In This Thread
RE: Python Pandas for loop/while loop question - by deanhystad - Mar-24-2020, 04:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas df inside a df question mbaker_wv 4 1,199 Dec-25-2022, 01:11 AM
Last Post: mbaker_wv
  Pandas usecols question rsearing 1 1,260 Aug-20-2022, 10:10 PM
Last Post: jefsummers
  Simple pandas question mcva 4 2,677 Dec-17-2021, 04:47 PM
Last Post: mcva
  Matplotlib scatter plot in loop with None values ivan_sc 1 2,294 Nov-04-2021, 11:25 PM
Last Post: jefsummers
  while loop mazeemagha 2 1,804 Aug-28-2021, 03:24 PM
Last Post: naughtyCat
Question I want to vectorize a really long for loop to improve performance Miregal1 1 1,993 Jul-18-2021, 11:13 AM
Last Post: jefsummers
  change for loop into numpy functions ToffiFaye 1 1,991 Feb-06-2021, 11:38 AM
Last Post: paul18fr
  Pandas question new2datasci 0 1,964 Jan-10-2021, 01:29 AM
Last Post: new2datasci
  Change classic loop to TensorFlow tf.while_loop vsl_neuro 0 1,790 Dec-15-2020, 07:57 AM
Last Post: vsl_neuro
  Python PDF merging from an excel pandas for loop siraero 0 2,214 Aug-16-2020, 09:34 AM
Last Post: siraero

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020