energy['Country'] = energy['Country'].str.replace(r" \(.*\)","")
I specifically do not understand what this part is doing -- str.replace(r" \(.*\)","")
Please let me know. Thanks!
energy['Country'] = energy['Country'].str.replace(r" \(.*\)","")
I specifically do not understand what this part is doing -- str.replace(r" \(.*\)","")
Please let me know. Thanks!
First, = energy['Country']
is getting the value from energy
that corresponds to 'Country'
.
This piece could be separated as follow:
obj = energy['Country']
energy['Country'] = obj.str.replace(r" \(.*\)","")
Next, the attribute str
is accessed from obj
.
Again separating that out:
obj = energy['Country']
attr = obj.str
energy['Country'] = attr.replace(r" \(.*\)","")
And then the function replace()
is called off of the value str
.
Note, the value str
here is not the same as the builtin class str. Instead it is an attribute of the class that is returned from energy['Country']
.