-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_fill_column.py
28 lines (26 loc) · 1.12 KB
/
auto_fill_column.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def auto_fill_column(rows, column_name):
"""
Take a column name (for exm: 'Title')
and list of columns that follows this pattern:
Title Actor ...
The Huge Wave John Doe ...
Alice Doe ...
Karl Muller ...
Titanic Leonardo Di Caprio ...
John Doe ...
And fills it up in-place (the original list gets modified), like this:
Title Actor ...
The Huge Wave John Doe ...
The Huge Wave Alice Doe ...
The Huge Wave Karl Muller ...
Titanic Leonardo Di Caprio ...
Titanic John Doe ...
Precondition: first row is not "" nor None
:param rows: list of rows in the csv file
:param column_name: string indicating the name of the field to update
:return: None,
"""
for row in rows:
if row[column_name] in ["", None]:
row[column_name] = last[column_name]
last = row