Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas column name equal to another column value

In [2]: df
Out[2]:
    A  B
0  p1  1
1  p1  2
2  p3  3
3  p2  4

In [3]: df.loc[df['B'] == 3, 'A']
Out[3]:
2    p3
Name: A, dtype: object

In [4]: df.loc[df['B'] == 3, 'A'].iloc[0]
Out[4]: 'p3'
Comment

pandas set one column equal to another

In [300]:
df.loc[df['colA'] == 'a', 'colC'] = df['colB']
df['colC'] = df['colC'].fillna(0)
df

Out[300]:
   id colA  colB  colC
0   0    a    13    13
1   1    a    52    52
2   2    b    16     0
3   3    a    34    34
4   4    b   946     0
Comment

PREVIOUS NEXT
Code Example
Python :: json python 
Python :: how to calculate the sum of a list in python 
Python :: groupby count pandas 
Python :: palindrome string python 
Python :: sort series in ascending order 
Python :: how to download instagram profile picture with the help of python 
Python :: delete an element by value from a list if it made of white spaces python 
Python :: python replace string 
Python :: Clear All the Chat in Discord Channel With Bot Python COde 
Python :: np array to tuple 
Python :: python 2 deprecated 
Python :: python read lines 
Python :: reading json file in python 
Python :: LoginRequiredMixin 
Python :: delete one pymongo 
Python :: the following packages have unmet dependencies python3-tornado 
Python :: error handling flask 
Python :: Extract column from a pandas dataframe 
Python :: how to update requirements.txt python 
Python :: python turtle get mouse position 
Python :: django models.py convert DateTimeField to DateField 
Python :: operator precedence in python 
Python :: how to use turtle in python in python 3.9 
Python :: how to sort a list of dictionary by value in descending order? 
Python :: making lists with loops in one line python 
Python :: python random liste 
Python :: how to convert a set to a list in python 
Python :: redirect in dajango 
Python :: print current line number python 
Python :: date strftime python 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =