You can handle the positive case using the following:

In [150]:
import re
df['fundleverage'] = '+' + df['name'].str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X') + '00'
df

Out[150]:
                 name fundleverage
0  BULL AXP UN X3 VON         +300
1    BULL ESTOX X12 S        +1200

You can use np.where to handle both cases in a one liner:

In [151]:
df['fundleverage'] = np.where(df['name'].str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X').str.isdigit(),  '+' + df['name'].str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X') + '00', '+100')
df

Out[151]:
                 name fundleverage
0  BULL AXP UN X3 VON         +300
1    BULL ESTOX X12 S        +1200

So the above uses the vectorised str methods strip, extract and isdigit to achieve what you want.

Update

After you changed your requirements (which you should not do for future reference) you can mask the df for the bull and bear cases:

In [189]:
import re
df = pd.DataFrame(["BULL AXP UN X3 VON", "BEAR ESTOX 12x S"], columns=["name"])
bull_mask_name = df.loc[df['name'].str.contains('bull', case=False), 'name']
bear_mask_name = df.loc[df['name'].str.contains('bear', case=False), 'name']
df.loc[df['name'].str.contains('bull', case=False), 'fundleverage'] = np.where(bull_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X').str.isdigit(),  '+' + bull_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X') + '00', '+100')
df.loc[df['name'].str.contains('bear', case=False), 'fundleverage'] = np.where(bear_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('x').str.isdigit(),  '-' + bear_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('x') + '00', '-100')
df

Out[189]:
                 name fundleverage
0  BULL AXP UN X3 VON         +300
1    BEAR ESTOX 12x S        -1200
Answer from EdChum on Stack Overflow
Top answer
1 of 1
2

You can handle the positive case using the following:

In [150]:
import re
df['fundleverage'] = '+' + df['name'].str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X') + '00'
df

Out[150]:
                 name fundleverage
0  BULL AXP UN X3 VON         +300
1    BULL ESTOX X12 S        +1200

You can use np.where to handle both cases in a one liner:

In [151]:
df['fundleverage'] = np.where(df['name'].str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X').str.isdigit(),  '+' + df['name'].str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X') + '00', '+100')
df

Out[151]:
                 name fundleverage
0  BULL AXP UN X3 VON         +300
1    BULL ESTOX X12 S        +1200

So the above uses the vectorised str methods strip, extract and isdigit to achieve what you want.

Update

After you changed your requirements (which you should not do for future reference) you can mask the df for the bull and bear cases:

In [189]:
import re
df = pd.DataFrame(["BULL AXP UN X3 VON", "BEAR ESTOX 12x S"], columns=["name"])
bull_mask_name = df.loc[df['name'].str.contains('bull', case=False), 'name']
bear_mask_name = df.loc[df['name'].str.contains('bear', case=False), 'name']
df.loc[df['name'].str.contains('bull', case=False), 'fundleverage'] = np.where(bull_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X').str.isdigit(),  '+' + bull_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('X') + '00', '+100')
df.loc[df['name'].str.contains('bear', case=False), 'fundleverage'] = np.where(bear_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('x').str.isdigit(),  '-' + bear_mask_name.str.extract(r"(X\d+|\d+X)\s", flags=re.IGNORECASE).str.strip('x') + '00', '-100')
df

Out[189]:
                 name fundleverage
0  BULL AXP UN X3 VON         +300
1    BEAR ESTOX 12x S        -1200
🌐
Esri Community
community.esri.com › t5 › arcgis-api-for-python-questions › str-object-has-no-attribute › td-p › 1053478
Solved: 'str' object has no attribute - Esri Community
September 14, 2021 - The clone_items function takes a list of Items. It seems like you are passing in the string item ids instead.
Discussions

AttributeError: 'str' object has no attribute 'get'
The formatting of your post is hella weird - how about you just include a link to your replit · For the catplot, you need to add a line fig=fig.fig before saving - as the test is not designed for standard object sns is returning · Am sorry for my formatting errors Jagaya, am new to this . More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
17
0
December 2, 2021
'Str' object has no attribute error?
The issue is that self.tasks is either a string or a list of strings. But you haven't shown where that is defined. More on reddit.com
🌐 r/learnpython
9
2
November 9, 2023
Result: Failure Exception: AttributeError: 'str' object has no attribute 'get' at project_id = req_body.get("project_id", None) this
Result: Failure Exception: AttributeError: 'str' object has no attribute 'get' Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 479, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/l... More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
July 10, 2023
python - AttributeError: 'str' object has no attribute - Stack Overflow
I'm pretty new to python programming and I wanted to try my hand at a simple text adventure game, but I've immediately stumbled on a roadblock. class userInterface: def __init__(self, roomID, More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python Forum
python-forum.io › thread-22378.html
AttributeError: 'str' object has no attribute 'xpath'
Dear Members, I am very new to python. I am using the following code to extract the details of each product. I am collecting product names from the original page and using each product link, I am collecting price, SKU, and frame information from th...
🌐
freeCodeCamp
forum.freecodecamp.org › python
AttributeError: 'str' object has no attribute 'get' - Python - The freeCodeCamp Forum
December 2, 2021 - The formatting of your post is hella weird - how about you just include a link to your replit · For the catplot, you need to add a line fig=fig.fig before saving - as the test is not designed for standard object sns is returning · Am sorry for my formatting errors Jagaya, am new to this .
🌐
Brainly
brainly.com › engineering › college › what does "str object has no attribute" mean in python?
[FREE] What does "str object has no attribute" mean in Python? - brainly.com
In Python, the error message "AttributeError: 'str' object has no attribute" indicates that you are trying to access a method or attribute that does not exist for string objects.
🌐
Reddit
reddit.com › r/learnpython › 'str' object has no attribute error?
r/learnpython on Reddit: 'Str' object has no attribute error?
November 9, 2023 -

I have some experience with programming in Java, C++, etc. and I am trying to write a simple "To-Do List" program to get used to Python. I'm running into the error: str object has no attribute "completed" when trying to iterate over the list of tasks, check their completion status, and display them.

Here are some relevant pieces of the program:

Constructor for the Task class

def __init__(self, task_name):

self.task_name = task_name

self.completed = False

In the ToDoList class (which holds a list of the task instances created by the user) this is the iteration throwing the error in question:

for idx, task in enumerate(self.tasks, start=1):

status = "Completed" if task.completed else "Incomplete"

print(f"{idx}. {task.task_name} - {status}")

I thought, potentially the problem lies in the fact that the enumerate function is grabbing the string value of the task instance, rather than the object itself, so maybe I can iterate over it the old fashioned way and get around it. So I tried it like this:

counter = 1

for task in self.tasks:

status = "Completed" if task.completed else "Incomplete"

print(f"{counter}. {task.task_name} - {status}")

counter += 1

Yet, it throws the same error. I know there is something I am missing or not understanding correctly here. What is it?

Thanks!

Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-str-object-has-no-attribute
AttributeError: 'str' object has no attribute 'X in Python | bobbyhadz
April 8, 2024 - The Python "AttributeError: 'str' object has no attribute" occurs when we try to access an attribute that doesn't exist on string objects.
🌐
Quora
quora.com › How-do-you-resolve-attributeerror-str-object-has-no-attribute-variables-Python-solutions
How to resolve 'attributeerror: 'str' object has no attribute 'variables'' (Python, solutions) - Quora
Fix the source of the string—load, instantiate, or look up the actual object—and avoid name shadowing so .variables is called on the correct type. ... RelatedHow do you resolve "attributeerror: 'dataframe' object has no attribute 'reshape'" (Python, Python 3.x, machine learning, deep learning, LSTM, development)?
🌐
GitHub
github.com › snakemake › snakemake › issues › 2724
AttributeError: 'str' object has no attribute 'get' · Issue #2724 · snakemake/snakemake
February 27, 2024 - Snakemake crashes. This is an extract from the log file. I've restarted the pipeline, so that only the "calling" part remains.
Author   ltalignani
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-object-has-no-attribute
How to fix AttributeError: object has no attribute - GeeksforGeeks
July 23, 2025 - To understand this error, we first have to know how to read the error message effectively. It typically consists of two parts: "AttributeError" and "Object has no attribute." The former indicates the type of error, and the latter suggests that the attribute we are trying to access does not exist for the object.
🌐
Reddit
reddit.com › r/learnpython › attributeerror: 'str' object has no attribute 'namelist' in python
r/learnpython on Reddit: AttributeError: 'str' object has no attribute 'namelist' in Python
September 22, 2020 -

At this line:
zipfile.ZipFile.extractall(zip, None, pwd=str.encode(pwd))
i allways get the error (in the title).
My zip path (as string zip) is like this:
zipFile = r'/home/itsthooor/This That/Empty.zip'

Where's the problem?
I saw a stack overflow post about it, but it didn't me help at all.

🌐
Reddit
reddit.com › r/learnpython › how do i fix this : attributeerror: 'str' object has no attribute 'current'
r/learnpython on Reddit: How do i fix this : AttributeError: 'str' object has no attribute 'current'
December 7, 2023 -

There is something wrong with this function. It shows no errors, but when I try to run it, It says AttributeError: 'str' object has no attribute 'current'. (BTW, i am trying to run it as a flet on spyder)

def leapyears(e):

days_in_month = {1: 31, 3: 31, 4: 30, 5:31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 }

month = int(EnterMonth_text.value)

year = int(EnterYear_text.value)

if year % 100 == 0:

if year % 400 == 0:

leap_year = True

elif year % 4 == 0:

leap_year = True

else:

leap_year = False

if month == 2 :

if leap_year:

days_in_month[2] = 29

else:

days_in_month[2]= 28

output_textfield.value= days_in_month[month]

page.update()

🌐
Sololearn
sololearn.com › en › Discuss › 2215037 › attributeerror-str-object-has-no-attribute-a
AttributeError: 'str' object has no attribute 'A'
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
GitHub
github.com › thingsboard › thingsboard-gateway › issues › 442
[BUG]AttributeError: 'str' object has no attribute 'get' · Issue #442 · thingsboard/thingsboard-gateway
December 17, 2020 - ""2020-12-17 12:52:30" - ERROR - [json_rest_uplink_converter.py] - json_rest_uplink_converter - 62 - 'str' object has no attribute 'get'", Traceback (most recent call last):, File "/usr/local/lib/python3.8/site-packages/thingsboard_gateway-2.5.5.2-py3.8.egg/thingsboard_gateway/connectors/rest/json_rest_uplink_converter.py", line 56, in convert, if datatype == 'timeseries' and (data.get("ts") is not None or data.get("timestamp") is not None):, AttributeError: 'str' object has no attribute 'get' Connector name (If bug in the some connector): gateway using rest.json connector
Author   alexvermeersch
🌐
Quora
quora.com › How-do-I-resolve-the-AttributeError-‘Str’-object-has-no-attribute-‘update’-in-Python
How to resolve the AttributeError: ‘Str’ object has no attribute ‘update’ in Python - Quora
Answer: A2A. So, in Python there are certain in built methods which you can directly use. Example: [code]L = [1, 2, 3] L.append(4) L.pop() L.insert(0, 10) [/code]And likewise many others. Similarly, strings have separate set of available built-in methods. [code]s="python" s.isdigit() s.islower...
🌐
Rssing
python1233.rssing.com › chan-44877200 › article18041.html
ItsMyCode: [Solved] AttributeError: ‘str’ object has no attribute ‘get’
Since we call the get() method on the string type, we get AttributeError. We can also check if the variable type using the type() method, and using the dir() method, we can also print the list of all the attributes of a given object.