Change the strings in student_grade_str into int

Question:

I wanna change the strings in student_grade_str into int.

Here is my code:

import pandas as pd 
from google.colab import drive

drive.mount('/content/drive')
student_grade_str =pd.read_csv('/content/drive/MyDrive/student_power_research.csv')      
for i in range( len( student_grade_str)):
  student_grade_int = list(map(int(),student_grade_str[i]))

And here’s
student_power_research.csvPicture version

I ran this code with google colab. Result is Keyerror: 0. I don’t understand what that error means.
Please tell me how to fix this.

Asked By: 侯凌群

||

Answers:

from google.colab import drive
drive.mount('/content/drive')
student_grade_str = pd.read_csv('/content/drive/MyDrive/student_power_research.csv')                  
student_grade_str = student_grade_str["Number"].astype(int)
student_grade_str = student_grade_str["Language"].astype(int)
student_grade_str = student_grade_str["Logic"].astype(int)

No need of for loop to convert string to int. Change your code as above.

Answered By: YJR
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.