pandas interpolate string

Solutions on MaxInterview for pandas interpolate string by the best coders in the world

showing results for - "pandas interpolate string"
Safiya
07 Jul 2018
1import pandas as pd
2
3s = pd.Series([None, None, 'red', 'red', None, 'blue', None, None])
4
5print(s.to_list())
6print(s.bfill().tolist())
7print(s.ffill().tolist())
8print(s.bfill().ffill().tolist())
9print(s.ffill().bfill().tolist())
10print(s.interpolate(method='pad').tolist())
11
12Output:
13[None, None, 'red', 'red', None, 'blue', None, None]
14['red', 'red', 'red', 'red', 'blue', 'blue', None, None]
15[None, None, 'red', 'red', 'red', 'blue', 'blue', 'blue']
16['red', 'red', 'red', 'red', 'blue', 'blue', 'blue', 'blue']
17['red', 'red', 'red', 'red', 'red', 'blue', 'blue', 'blue']
18[None, None, 'red', 'red', 'red', 'blue', 'blue', 'blue']