0

These two lines of code print the output shown below.

variable = df1['Name'].str[11:14]
print(variable.head(2))
0   025
1   012

However, when I try to convert the string to an integer I get this error "TypeError: cannot convert the series to <class 'int'>"

variable = df1['Name'].str[11:14]
variable = int(variable)
print(variable.head(2))

How do I convert this string to an integer?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

0

variable is not a string, but a Pandas series of strings.

The way I would do it is variable = variable.astype(int), but you have a few options...

This post should help you out.