Question

In: Computer Science

Using Python, I am trying to integrate 'iloc' into the line of code below? This line...

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:)

Solutions

Expert Solution

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.


Related Solutions

I am trying to integrate a Singleton Pattern into this code I had previously made. Here...
I am trying to integrate a Singleton Pattern into this code I had previously made. Here is my code to a previous project: radius = float(input("Please enter the radius: ")) area = 3.14 * radius**2; print("The area is ", area, "square units.") For this project it must be coded in python. Here are the instructions for the project for reference. Implementing Design Patterns with Python Software Design Patterns may be thought of as blue prints or recipes for implementing common...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
Working with Python. I am trying to make my code go through each subject in my...
Working with Python. I am trying to make my code go through each subject in my sample size and request something about it. For example, I have my code request from the user to input a sample size N. If I said sample size was 5 for example, I want the code to ask the user the following: "Enter age of subject 1" "Enter age of subject 2" "Enter age of subject 3" "Enter age of subject 4" "Enter age...
In Python we will be using the below code for the problem: rainfile=open('rainfall.txt') for line in...
In Python we will be using the below code for the problem: rainfile=open('rainfall.txt') for line in rainfile: values = line.split() #print(values) print (values[0], 'had', values[1], 'inches of rain.') rainfile.close( ) The following is the text from rainfall.txt Akron 26.81 Albia 37.65 Algona 30.69 Allison 33.64 Alton 27.43 AmesW 34.07 AmesSE 33.95 Anamosa 35.33 Ankeny 33.38 Atlantic 34.77 Audubon 33.41 Beaconsfield 35.27 Bedford 36.35 BellePlaine 35.81 Belleveu 34.35 Blocton 36.28 Bloomfield 38.02 Boone 36.30 Brighton 33.59 Britt 31.54 Buckeye 33.66 BurlingtonKBUR...
I am trying to do edge detection using matlab. I have posted code here. It does...
I am trying to do edge detection using matlab. I have posted code here. It does not give any error but it's not running it at all. So please help me to fix it and also exaplin each line of this code pls. Thanks! i = imread('C:\Users\Amanda\Desktop"); I = rgb2gray(1i); BW1 = edge(I,'prewitt'); BW2= edge(I,'sobel'); BW3= edge(I,'roberts'); subplot (2,2,1); imshow(I); title('original'); subplot(2,2,2); imshow(BW1); title('Prewitt'); subplot(2,2,3); imshow(BW2); title('Sobel'); subplot(2,2,4); imshow(BW3); title('Roberts');
C# programming. Comment/Explain the below code line by line. I am having a hard time following...
C# programming. Comment/Explain the below code line by line. I am having a hard time following it. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Nth_prime {     class Program     {         public static bool isPrime(int number)         {             int counter = 0;             for (int j = 2; j < number; j++)             {                 if (number % j == 0)                 {                     counter = 1;                     break;                 }             }             if (counter == 0)             {                 return true;             }             else             {                 return false;             }         }...
Assembly Question: I am trying to annotate this code and am struggling to understand what it...
Assembly Question: I am trying to annotate this code and am struggling to understand what it is doing. Can someone please add comments? .data .star: .string "*" .line: .string "\n" .input: .string "%d" .count: .space 8 .text .global main printstars: push %rsi push %rdi _printstars: push %rdi mov $.star, %rdi xor %rax, %rax call printf pop %rdi dec %rdi cmp $0, %rdi jg _printstars mov $.line, %rdi xor %rax, %rax call printf pop %rdi pop %rsi ret printstarpyramid: mov %rdi,...
I am trying to write a code in C for a circuit board reads in a...
I am trying to write a code in C for a circuit board reads in a temperature from a sensor on the circuit board and reads it onto a 7-segment LED display. How exactly would you code a floating 2 or 3 digit reading onto the LED display? I am stuck on this part.
I am trying to make a program in Python that opens a file and tells you...
I am trying to make a program in Python that opens a file and tells you how many lines, vowels, consonants, and digits there are in the file. I got the print out of lines, digits, and consonants, but the if statement I made with the vowels list isn't recognizing them. How can I make the vowels go through the if statement with the list? Am I using the wrong operator? Here is my program #Assignment Ch7-1 #This program takes...
I am trying to make a Risk Management tool in Python. I have it partially started....
I am trying to make a Risk Management tool in Python. I have it partially started. The scenario is that the Project Manager needs to be able to log on and enter information ( the required information is located in the code). I then need to capture that data and store it in an array with the ability to call back and make changes if necessary. Could you please help me out and explain what was done? Current code: Start...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT