Python Forum
Calculated DF column from dictionary value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculated DF column from dictionary value
#1
I would like to make a calculated column as shown here ('new'), from the exiting 'data' column (which is a list with a dictionary inside). It works in this code.

data = [10,[{'self': 'https://elia.atlassian.net/rest/api/3/customFieldOption/10200', 'value': 'IT-Sourced Changes 2022', 'id': '10200'}],30]
df = pd.DataFrame(data, columns=['Data'])
df['new'] = df.Data.explode().str['value']
df.head(3)
However, when I try it on an existing dataframe, I get 'ValueError: cannot reindex from a duplicate axis'. Not sure why.

https://imgur.com/a/B4qEOWa
Reply


Messages In This Thread
Calculated DF column from dictionary value - by plantagenet - Sep-15-2022, 12:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to calculated how many fail in each site(s) in csv files SamLiu 4 1,312 Sep-26-2022, 06:28 AM
Last Post: SamLiu
  Can I format decimal places by column with a dictionary? Mark17 2 2,582 Dec-28-2020, 10:13 PM
Last Post: Mark17
  Using OpenPyXL How To Read Entire Column Into Dictionary jo15765 1 2,690 Jun-08-2020, 04:10 AM
Last Post: buran
  How do I print a returned variable calculated in another function? RedSkeleton007 3 3,547 Jul-10-2018, 12:10 PM
Last Post: buran
  Sorting values calculated in python stumunro 4 3,984 Sep-13-2017, 06:09 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

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