In [1]:
import pandas as pd
In [2]:
ds = pd.Series([1, 2, 3, 4])
ds
Out[2]:
0    1
1    2
2    3
3    4
dtype: int64
In [3]:
def test(x):    
    if not x % 2:
        return x + 1
    else:
        return x
    
ds.apply(test)
Out[3]:
0    1
1    3
2    3
3    5
dtype: int64
In [5]:
ds.apply(lambda x: x + 1 if not x % 2 else x)
Out[5]:
0    1
1    3
2    3
3    5
dtype: int64

Homework

In [7]:
cities = pd.Series(
    {'Dnepr': 1000000, 'Kiev': 3000000, 'Paris': 2300000, 'Berlin': 3800000},
)
cities
Out[7]:
Dnepr     1000000
Kiev      3000000
Paris     2300000
Berlin    3800000
dtype: int64
In [8]:
cities2 = pd.Series(cities.index)
cities2
Out[8]:
0     Dnepr
1      Kiev
2     Paris
3    Berlin
dtype: object
In [12]:
# Примените функцию lambda к серии cities2, чтобы получить вариант вывода ниже (если в названии города есть литера 'e'):
'''
0     Dnepr!!!
1        Kiev
2        Paris
3     Berlin!!!
dtype: object
'''

print('Ваше решение')
Ваше решение
In [11]:
# примените функцию к серии cities2, чтобы получить вариант вывода ниже
'''
0      D-n-e-p-r
1          Paris
2    B-e-r-l-i-n
3         London
'''

print('Ваше решение')
Ваше решение
In [ ]:
 
In [ ]: