Python Forum
Add column based on others
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add column based on others
#1
Hi there,

This is a dataframe with glacial lakes and their volume:

data = {'Volume':  ['50', '100', '100', '90', '60', '200', '150', '80', '70'],
        'GlacierID': ['a', 'a', 'b', 'b', 'c', 'd', 'd', 'd', 'e']}
dataframe= pd.DataFrame(data, columns = ['Volume', 'GlacierID'])
I would like to create a third column 'LakeID' assigning every value a new ID, which is composed of 'GlacierID' and an extra number according to the number of lakes. Ideally the largest volume gets number 1.

The output should look like this: (My real dataframe is much larger, so I can't do it manually)

Volume GlacierID LakeID
0     50         a     a2
1    100         a     a1
2    100         b     b1
3     90         b     b2
4     60         c     c1
5    200         d     d1
6    150         d     d2
7     80         d     d3
8     70         e     e1
I really don't have any idea how to do this so I cannot include any further coding.

Thank you!
Reply


Messages In This Thread
Add column based on others - by timste - Mar-27-2021, 10:52 AM
RE: Add column based on others - by eddywinch82 - Mar-27-2021, 09:05 PM
RE: Add column based on others - by timste - Mar-27-2021, 09:52 PM
RE: Add column based on others - by jefsummers - Mar-29-2021, 12:17 AM
RE: Add column based on others - by devesh_sahu - Apr-01-2021, 09:20 AM
RE: Add column based on others - by devesh_sahu - Apr-01-2021, 09:24 AM
RE: Add column based on others - by timste - Apr-01-2021, 09:49 AM
RE: Add column based on others - by devesh_sahu - Apr-03-2021, 07:37 AM
RE: Add column based on others - by devesh_sahu - Apr-03-2021, 07:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 894 Dec-12-2022, 03:22 AM
Last Post: ill8
  New Dataframe Column Based on Several Conditions nb1214 1 1,811 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Pandas Data frame column condition check based on length of the value aditi06 1 2,698 Jul-28-2021, 11:08 AM
Last Post: jefsummers
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,269 May-17-2021, 07:02 AM
Last Post: lorensa74
  Extracting rows based on condition on one column Robotguy 2 2,222 Aug-07-2020, 02:27 AM
Last Post: Robotguy
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 4,290 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  Pandas - Dynamic column aggregation based on another column theroadbacktonature 0 3,064 Apr-17-2020, 04:54 PM
Last Post: theroadbacktonature
Question Dividing a single column of dataframe into multiple columns based on char length darpInd 2 2,474 Mar-14-2020, 09:19 AM
Last Post: scidam
  Sum product multiple Dataframes based on column headers. Lastwizzle 0 3,832 May-21-2019, 04:05 PM
Last Post: Lastwizzle
  Create selection box to pass string value based on uniques in Excel column sneakysnek 1 2,508 Nov-18-2018, 07:29 PM
Last Post: Stefanovietch

Forum Jump:

User Panel Messages

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