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 ::  
Python :: python write file 
Python :: pandas remove column 
Python :: python - row slice dataframe by number of rows 
:: import image 
Python :: multiple line input python 
Python :: add text to pygame window 
Python :: what is join use for in python 
:: how to commenbt code in python 
Python ::  
:: numpy standard deviation 
Python :: how to close a webpage using selenium driver python 
Python :: first 5 letters of a string python 
Python :: free python script hosting 
Python :: channel lock command in discord.py 
Python :: select specific rows from dataframe in python 
Python :: python delete white spaces 
:: get list file endswith python 
Python :: how to load keras model from json 
Python :: isprime python 
Python :: pd count how many item occurs in another column 
Python :: tkinter frame example 
Python :: n-largest and n-smallest in list in python 
Python :: django urlpattern 
:: tdmq python 
:: python list to bytes 
Python :: python pywhatkit 
:: How to search where a character is in an array in python 
::  
ADD CONTENT
Topic
Content
Source link
Name
6+3 =