When I use df.apply(pd.Series.str.upper) shows me an error -
Although df.apply(pd.Series.min) is running absolutely fine! and df.apply(lambda x: x.str.upper()) is running fine too.
df = pd.DataFrame(
{
"Name":[
"Harry","Sam", "Jack"], "Gender": ["M","M","F"]})
df.apply(pd.Series.str.lower)
Error - Series' object has no attribute '_inferred_dtype'
CodePudding user response:
When you apply pd.Series.str
its converting each row to String Series
type hence lower
method would not work unless you apply individually like below
df = pd.DataFrame(
{
"Name":[
"Harry","Sam", "Jack"], "Gender": ["M","M","F"]
}
)
df.apply(pd.Series.str) # Check output in below image
Its clear if you want to apply lower
you have to iteratively apply at every instance hence 'lambda' would be useful
df.apply(lambda x: x.str.lower())
CodePudding user response:
Simply adapt your upper()
approach, it should give you the expected result:
df.apply(lambda x: x.str.lower())