In: Computer Science
Using Python, I am trying to integrate 'iloc' into the line of code below? This line is replacing all the '1' values across my .csv file and is throwing off my data aggregation. How would I implement 'iloc' so that this line of code only changes the '1's integers in my 'RIC' column?
patient_data_df= patient_data_df.replace(to_replace=[1], value ="Stroke")
Thank you:)
Python code:-
import pandas as pd
data = pd.read_csv("C:/Users/Sai/Videos/book1.csv")#read csv file
with its location
print(data)#Simply print CSV file
print('\n')
new=data.iloc[:,[4]]
#Here we used iloc function to select column to be modify and
#4 show 4th position of column to be replace old value to new
value
data = data.replace(1,'new value')
#here we change '1' integer occur in perticular column
#it will replace with new one belong to only thst column.
print(data)
Output:- Firstly Show Csv File and then Modification Show Using iloc.