str accessor
noun
say it: “dot S-T-R ak-SESS-er” /dɑt ˌɛs ti ˈɑr ækˈsɛsər/
In pandas, the .str part of a text column, which gives it string tools such as lowercasing and trimming spaces that work on every value at once.
What is the str accessor in pandas?
The str accessor is .str, read "dot s t r": it gives a pandas text column the string tools, such as strip(),
lower(), title() and contains(), and each one works on every value in the column at once, with no loop.
import pandas as pd
names = pd.Series([" maria LOPEZ ", "Sam Chen"])
print(names.str.strip().str.title()) # "Maria Lopez", "Sam Chen"
In a sentence
- “The str accessor tidied all 450 runner names in one line.”
- “Through the str accessor, lower() works on the whole hometown column.”
Level: Journeyman · More Python terms at this level
Updated