-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescription_references.py
30 lines (20 loc) · 1.24 KB
/
description_references.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
29
30
# To build the description with references you need at least 1 'Source_i' column with it's associated 'Source_i_URL' column
# The description column must also be titled 'Description'
import pandas as pd
# Import CSV (Rename this); Make sure it's in the same working directory as the script
df = pd.read_csv('imported_data.csv')
def build_desc(row):
i = 1
if not pd.isna(row[f'Source_{i}_URL']):
row['Description'] = f'<p>{row["Description"]}<sup class="pix-reference pix-reference__nav" prefix-config-display-text="{row["Source_" + str(i)]}" prefix-config-link="{row["Source_" + str(i) + "_URL"]}"><a id="ref{i}_home" href="#">[{i}]</a></sup>'
i += 1
while not pd.isna(row[f'Source_{i}_URL']):
row['Description'] = f'{row["Description"]}<sup class="pix-reference pix-reference__nav" prefix-config-display-text="{row["Source_" + str(i)]}" prefix-config-link="{row["Source_" + str(i) + "_URL"]}"><a id="ref{i}_home" href="#">[{i}]</a></sup>'
i += 1
if f'Source_{i}_URL' not in df.columns:
break
row['Description'] = f'{row["Description"]}</p>'
return row['Description']
df['Description'] = df.apply(build_desc, axis = 1)
# Download xlsx (Relevant renamed XLSX)
df.to_excel('exported_data.xlsx', index = False)