Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

replace column values pandas

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

dataframe change column value

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

replace values of pandas column

df.loc[df['column'] == 'column_value', 'column'] = 'new_column_value'
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 :: django or flask 
Python :: socket.accept python 
Python :: reverse the string in python 
Python :: arithmetic operators in python 
Python :: python glob how to read all txt files in folder 
Python :: lists in python 
Python :: python x = x + 1 
Python :: docstring 
Python :: update python version pycharm 
Python :: opencv python rgb to hsv 
Python :: eval() function in python 
Python :: django email verification 
Python :: python sort a list by a custom order 
Python :: what is gui in python 
Python :: python string operations 
Python :: python boto3 put_object to s3 
Python :: armstrong number function 
Python :: how to flatten list of lists in python 
Python :: time series python 
Python :: 2)Write a function that checks whether a number is in a given range (inclusive of high and low) python 
Python :: pong code python 
Python :: how to access dictionary inside an array python 
Python :: detect grayscale image in python opencv 
Python :: python code to calculate encryption time 
Python :: pyglet on button press 
Python :: exchange sort python 
Python :: findout age in python 
Python :: elavon converge api python tutorial 
Python :: pypi modules for 3d gui 
Shell :: remove postgresql ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =