Skip to content

Commit aabd76e

Browse files
committed
add csv metadata post-process example
1 parent 0148832 commit aabd76e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This script takes an eLabFTW exported CSV file as input
2+
# and processes the metadata into new columns
3+
# it requires the "pandas" library
4+
import pandas as pd
5+
import json
6+
7+
def get_fields(metadata):
8+
"""Extract the name and value of extra field"""
9+
try:
10+
metadata_dict = json.loads(metadata)
11+
return {name: field.get('value', None) for name, field in metadata_dict['extra_fields'].items()}
12+
except (json.JSONDecodeError, KeyError, TypeError):
13+
return {}
14+
15+
df = pd.read_csv('data/antibodies-export-from-elab.csv')
16+
17+
for index, row in df.iterrows():
18+
new_fields = get_fields(row['metadata'])
19+
for name, value in new_fields.items():
20+
df.at[index, name] = value
21+
22+
df.to_csv('output.csv', index=False)

0 commit comments

Comments
 (0)