Python Forum
Referencing string names in df to outside variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Referencing string names in df to outside variables
#2
You almost never want to loop through a dataframe. A lot of the point of dataframes is the ability to do things as a vector.
So, not using a loop (this is untested as I don't have your dataframe)
nfl_df['Home Wins'] = (nfl_df['Home Score'] > nfl_df['Visitor Score'])
nfl_df['Margin'] = abs(nfl_df['Home Score'] - nfl_df['Visitor Score'])
I would also just extract a set of the team names. Using a set eliminates duplicates
Reply


Messages In This Thread
RE: Referencing string names in df to outside variables - by jefsummers - Nov-16-2021, 12:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variables in a SCPI string thomaswfirth 3 1,141 May-22-2023, 05:04 PM
Last Post: thomaswfirth
  name 'lblstatus' is not defined when referencing a label KatManDEW 4 1,745 Apr-21-2022, 12:33 PM
Last Post: KatManDEW
  Dictionary Referencing nickdavis2017 1 1,689 Nov-20-2021, 06:24 PM
Last Post: deanhystad
  Referencing a fixed cell Mark17 2 2,196 Dec-17-2020, 07:14 PM
Last Post: Mark17
Sad need help in referencing a list n00bdev 2 1,947 Nov-01-2020, 12:06 PM
Last Post: buran
  Issue referencing new instance from other class nanok66 3 2,373 Jul-31-2020, 02:07 AM
Last Post: nanok66
  referencing another method in a class Skaperen 6 2,864 Jul-02-2020, 04:30 AM
Last Post: Skaperen
  Theory behind referencing a dictionary rather than copying it to a list sShadowSerpent 2 2,211 Mar-24-2020, 07:18 PM
Last Post: sShadowSerpent
  Creating local variables from a string peckjonk 2 2,283 Feb-15-2020, 06:07 PM
Last Post: ndc85430
  "not defined" error in function referencing a class Exsul 2 3,804 Mar-27-2019, 11:59 PM
Last Post: Exsul

Forum Jump:

User Panel Messages

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