Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

replace column values pandas

df['column'] = df['column'].str.replace(',','-')
df
Comment

dataframe change specicf values in column

df['column name'] = df['column name'].replace(['old value'],'new value')
Comment

dataframe change column value

df["column1"].replace({"a": "x", "b": "y"}, inplace=True)
Comment

how to change values in dataframe python

energy['Country'] = energy['Country'].replace(['Afghanistan','Albania'],['Sa','lol'])
Comment

change value in dataframe

# change value in column_where_to_change and in the row where column_name == column_value
df.loc[df['<column_name>']=='column_value', '<column_where_to_change>'] = '<new_value>'
Comment

change value of column in pandas

# Importing the libraries
import pandas as pd
import numpy as np
  
# data
Student = {
    'Name': ['John', 'Jay', 'sachin', 'Geetha', 'Amutha', 'ganesh'],
    'gender': ['male', 'male', 'male', 'female', 'female', 'male'],
    'math score': [50, 100, 70, 80, 75, 40],
    'test preparation': ['none', 'completed', 'none', 'completed',
                         'completed', 'none'],
}
  
# creating a Dataframe object
df = pd.DataFrame(Student)
  
# Applying the condition
df.loc[df["gender"] == "male", "gender"] = 1
Comment

PREVIOUS NEXT
Code Example
Python :: python script header 
Python :: pyodbc sql save pandas dataframe 
Python :: replace values of pandas column 
Python :: dataframe column data type 
Python :: python getter decorator 
Python :: how to print palindrome in 100 between 250 in python 
Python :: python set negative infinity 
Python :: python average 
Python :: how to round a number down in python 
Python :: Django Check hashed Password 
Python :: python divide floor 
Python :: ip regex python 
Python :: pandas group by multiple columns and count 
Python :: replace character in column 
Python :: dataframe summary pandas 
Python :: index of max in tensor 
Python :: pandas set condition multi columns 
Python :: pytorch view -1 meaning 
Python :: starting vscode on colab 
Python :: joblib 
Python :: how to draw a rectangle in pygame 
Python :: calcutalte average python 
Python :: python currency 
Python :: python os.name mac 
Python :: python reverse geocode 
Python :: how to make a class in python 
Python :: Scaling Operation in SkLearn 
Python :: mac why is python installed in usr and application 
Python :: python frame in a frame 
Python :: check if string is empty python 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =