Python Forum
attempt to split values from within a dataframe column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
attempt to split values from within a dataframe column
#10
It looks like the issue might be due to the way you're trying to access the values in the year3paytest column. Instead of directly using [0][0], try iterating through the rows or using apply again to split the values. # Assuming semiannualpayments returns a tuple like (1500, 1505) cleandata["year3paytest"] = cleandata.apply(lambda x: semiannualpayments(x["owneroccupancycode"], x["year3total"], x["county"]), axis=1) # Split the tuples into two separate columns cleandata["year3pay1"] = cleandata["year3paytest"].apply(lambda x: x[0]) cleandata["year3pay2"] = cleandata["year3paytest"].apply(lambda x: x[1]) This should help you split the tuple values into two separate columns without running into the KeyError. Give it a try and see if it resolves the issue!
Reply


Messages In This Thread
RE: attempt to split values from within a dataframe column - by AdamHensley - Jun-20-2024, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create new column in dataframe Scott 10 645 Jun-30-2024, 10:18 PM
Last Post: Scott
  Putting column name to dataframe, can't work. jonah88888 2 2,065 Jun-18-2024, 09:19 PM
Last Post: AdamHensley
  concat 3 columns of dataframe to one column flash77 2 1,076 Oct-03-2023, 09:29 PM
Last Post: flash77
  HTML Decoder pandas dataframe column mbrown009 3 1,291 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Increase df column values decimals SriRajesh 2 1,223 Nov-14-2022, 05:20 PM
Last Post: deanhystad
  New Dataframe Column Based on Several Conditions nb1214 1 1,938 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  pandas: Compute the % of the unique values in a column JaneTan 1 1,898 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  Remove specific values from dataframe jonah88888 0 1,788 Sep-24-2021, 05:09 AM
Last Post: jonah88888
  update values in one dataframe based on another dataframe - Pandas iliasb 2 9,755 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  Setting the x-axis to a specific column in a dataframe devansing 0 2,162 May-23-2021, 12:11 AM
Last Post: devansing

Forum Jump:

User Panel Messages

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