i am having a problem while working with apply method. so, i am trying to make the first and last letter of a series uppercase. First i have made a simple series i.e
s1 = pd.Series(['pandas','python','javascript','c#'])
s1
The output:
0 pandas
1 python
2 javascript
3 c#
dtype: object
When I make a simple function and run it. It works fine with no issue and gives me the output that I was hoping for.
def upp(x):
for i in x:
print(f'{i[0].upper()}{i[1:-1].lower()}{i[-1].upper()}')
upp(s1)
Output:
PandaS
PythoN
JavascripT
C#
However, the output is not a series type, as I would want it to do further analysis. I ran a type method to check the type.
type(upp(s1))
Output:
NoneType
So, i guessed i have to use the apply method to get a series datatype. But, when i run apply method with the function. the result was not what i was hoping for.
def upp(x):
for i in x:
print(f'{i[0].upper()}{i[1:-1].lower()}{i[-1].upper()}')
s1.apply(upp)
Output:
PP
HH
PP
PP
YY
TT
HH
OO
NN
JJ
AA
VV
AA
CC
##
0 None
1 None
2 None
3 None
dtype: object
Can anyone explain to me what is happening and where i am doing wrong and give more information on how to use and not use apply method? I am a beginner and practicing some questions. It will be a great help to understand this concept.