-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from NFDI4BIOIMAGE/export_csv
Export training materials as CSV
- Loading branch information
Showing
6 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,5 @@ parts: | |
|
||
- caption: Appendix | ||
chapters: | ||
- file: export/readme | ||
- file: imprint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Open data | ||
|
||
Following FAIR data and open access principles, you can download the resources made accessible in this website, e.g. from our [github](https://github.com/NFDI4BIOIMAGE/training) repository. | ||
|
||
For user's convenience we created some automatically updated CSV exports of specific data: | ||
* [training_materials.csv](training_materials.csv) | ||
|
||
[Get in touch](https://github.com/NFDI4BIOIMAGE/training/issues/new) if you need other data exported as CSV files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This file exports selected data as csv file | ||
source = "./resources/" | ||
destination = './docs/export/training_materials.csv' | ||
|
||
# We filter by specific content types | ||
filter_types = ['course', 'tutorial', 'video', 'blog', 'workshop', 'notebook'] | ||
|
||
# We keep only selected columns | ||
selected_columns = ["name", "authors", "url", "tags", "license", "description"] | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Do not modify anything further down | ||
from generate_link_lists import load_dataframe | ||
|
||
df = load_dataframe(source) | ||
|
||
# Convert arrays to strings | ||
def array_to_string(arr): | ||
if type(arr) != list: | ||
return str(arr) | ||
return ', '.join(map(str, arr)) | ||
|
||
df['tags'] = df['tags'].apply(array_to_string) | ||
df['authors'] = df['authors'].apply(array_to_string) | ||
df['type'] = df['type'].apply(array_to_string) | ||
df['license'] = df['license'].apply(array_to_string) | ||
|
||
|
||
# filter type by by | ||
def contains_filter_word(text, words): | ||
return any(word in text for word in words) | ||
df = df[df['type'].apply(lambda x: contains_filter_word(x, filter_types))] | ||
|
||
# select columns | ||
df = df[selected_columns] | ||
|
||
# save selected data | ||
df.to_csv(destination, index=False) | ||
|
||
num_rows = df.shape[0] | ||
print(f"Exported {num_rows} rows.") |