pandas create column from another column

Solutions on MaxInterview for pandas create column from another column by the best coders in the world

showing results for - "pandas create column from another column"
Giulia
23 Feb 2018
1# Creates a new column 'blue_yn' based on the existing 'color' column
2# If the 'color' column value is 'blue' then the new column value is 'YES'
3df['blue_yn'] = np.where(df['color'] == 'blue', 'YES', 'NO')
4# Can also do this using .apply and a lambda function
5df['blue_yn']= df['color'].apply(lambda x: 'YES' if (x == 'blue') else 'NO') 
Jenna
29 Jul 2016
1def label_race (row):
2   if row['eri_hispanic'] == 1 :
3      return 'Hispanic'
4   if row['eri_afr_amer'] + row['eri_asian'] + row['eri_hawaiian'] + row['eri_nat_amer'] + row['eri_white'] > 1 :
5      return 'Two Or More'
6   if row['eri_nat_amer'] == 1 :
7      return 'A/I AK Native'
8   if row['eri_asian'] == 1:
9      return 'Asian'
10   if row['eri_afr_amer']  == 1:
11      return 'Black/AA'
12   if row['eri_hawaiian'] == 1:
13      return 'Haw/Pac Isl.'
14   if row['eri_white'] == 1:
15      return 'White'
16   return 'Other'
17
18df.apply(lambda row: label_race(row), axis=1)
queries leading to this page
python add column based on another columnpandas add column as function of another columncreate new column pandas from other columnspython make a new df column that 27s an edit of another df columnpandas making new dataframe using other columnscreate a new dataframe with selected columns from another dfhow to make a new dataframe with columns from anotherpython create a column as function of othercreate new columns pandas from another columnpandas new columns from other columnsdataframe create column from other columnspandas add column with value from another columncreate a column base on other columnspandas add column from another columncreate new column from other columns of dataframe new column based on another column pandashow to create a new pandas column using other columnscreate new column based on another column if pandaspandas caclulate column based on other columnspanda dataframe new column based on otherscreate a new column based on another pandashow to create a new column based on other columns in pandasdataframe add a column based on other columnscreate new column if two columns 3d 1 pandaspandas dataframe new df with certain columns from another dataframepandas create new column based on other columns in listpandas create new column based on values from other columnspandas create new column from existing and alter stringpandas create a column based on another columnhow to create new column in dataframe based on other copython create new dataframe columns using otherdataframe new column based on other columnshow to add a new column from other columns in pandascreate new column pandas based on other columnscreate new column based on another pandashow to create new columns from data within our column pandascreate new column based on other columns pandascreate new column pandas based on other columnhow to add columns in pandas using a common column in another dataframepandas create column from other columncalculate column out of two other columns pandaspandas new column based on other columnspandas create dataframe with columns from another dataframecreate df with only columnspython create a new column based on another columnpandas new column from other columnspandas create new column based on other dataframepd create column from anotherhow to generate a column using another columns in csvmake new column based on other columns pandascreate a column based on another column pandaspandas create column based on another columnpandas create new column based on operation of other columnscreate a new column based on another column pandas in a differnet tablecreate a new column in pandas based on other columnsdataframe create new column based on other columnsdefine a new column formula from other columns pandasadd new column if value in other column is the samepython create a column with values from other columnscreate new pandas column by running function over other columncreate a column based on another dataframe column pandaspandas create columns from other columnspython if 2 columns meet criteria create column valuepandas create a new column from other columnspandas add column based on another columnpandas create new column in place 3dtruepython create new column based on other columnspandas create a new column based on another columncreate a dataframe using another collumnhow to create new columns from another columns in pandaspandas make new column based on another columnpython add columns according to column valuesif column has name make another coulmn 0 pandasnew column from other columns pandaspandas assign column from another dataframecreate a new column from other dataframehow to add a column based on another column pandaspython create new column add other columns valuespandas new column function of other columnspandas dataframe create new column based on other columnscreate new columns from a given column pandasadd new column and acess other columnpandas generate column from other columnscreate new column from text in another columns pandashow to create a new column in pandas based on the values of another columndataframe create new column from other columnspandas create column from another dataframe column valuecreate a new column in pandas based on previous columnhow to create new column from another columns in pandaspandas create dataframe with columns from anothercreate a new df from columns of another dfcreate new dataframe with some columnshow to create a new column in dataframe using other columnscreate new dataframe from columns of other dataframepandas create column based on other columnshow to create new column in panda inside functioncreate new pandas column by function of othercreate dataframe column from other columnscreate a new column based on another column pandashow to create a column in pandas dataframe after another columncreate column from other columns pandascreate a dataframe with columns from another dataframecreate pandas column from other columndataframe add multiple columns based on other columnscreate one column from a dataframepandas calculate column based on othercreate a new column based on another columns in pandaspandas create new column based on other columnspandas create column from function with other columns as parameterscreate dataframe from columns of another dataframecreate new columns in pandas efficientlypandas create new columns based on other columnscreate a new column from existing columns pandas while applying a functioncrate a new column in pandas based on other columns in dfcreate a new column in df with values of another columncreate a new column in pandas based on other columns distributioncreate a new column based on other columns pandasin pandas how to create new column based on the value of another columnadd df column with df apply valueshow to create a new column from others pandashow to make one column from other columns in pandascreate new column in dataframe python based on other columnsadd column to pandas dataframe based on value in columnscreate dataframe with columns for other dataframepython pandas new column based on other columnsif a df column value is same for both rows then create a new columnpopulate a columns of a dataframe from another dataframe in pythondataframe create data and column from other columnscreate new column in pandas based on other columnscreate dataframe using columns of another dataframepandas create new column based on another columncreate column from other column pandaspandas dataframe create a column based on the value of another columncreate new column in dataframe using other columnspandas add columns from another dataframeput one dataframe 27s column to another new dataframehow to create a new column in pandas based on another columnpandas create new column applyapply but add new columnshow to column for each row based on other columns in pandaspandas create column from another columncreate a new column in pandas based on other columns condetionpandas create new column from another columncreate dataframe from another dataframe columnpython pandas create new column based on other columnspandas column based on another columncreate dataframe from other columns pythoncreate a new column in pandas based on another column hot to create a new dataframe with some columns of other dataframehow to create a new column based on another column pandaspandas make new column from other columnscreate column based on another column pandaspython new column znorm other columnpython create a df using columns from another dfcreate new column in pandas dataframe based on other columnspandas use column of another dataframecreate new dataframe with another dataframe columnscreate new column based on another column pandascreate a new dataframe from another df columnsadd a new column to a dataframe based on other columnspandas new column based on other columntcreate new dataframe with columns from another dataframe pythoncreate new column in dataframe using calculations on other columnsdataframe new column based on another columnpandas new column based on another columnget a column based on other columns in pythonpandas add column based on other columnspandas create column from another column