diff --git a/aggregated-results/sdg-profiles-statistics.ipynb b/aggregated-results/sdg-profiles-statistics.ipynb index 091994ba209132a5e3be0e264193b59f0fc7a862..009395fd33a818e1e945b52113edc0ad9639678a 100644 --- a/aggregated-results/sdg-profiles-statistics.ipynb +++ b/aggregated-results/sdg-profiles-statistics.ipynb @@ -24,7 +24,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Install packages" + "## Install packages (optional)" ] }, { @@ -112,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -121,7 +121,7 @@ "(244, 29)" ] }, - "execution_count": 5, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -132,14 +132,14 @@ "url = 'https://gitlab.fabcloud.org/fl-management/fl-sdgs/sdg-workshop/-/raw/master/'\n", "url = url + 'aggregated-results/FabLab-SDGProfile-Registration.xlsx' \n", "timestamp = datetime.datetime.utcnow()\n", - "profiles=pd.read_excel(url, 'processing', index_col=27)\n", + "#profiles=pd.read_excel(url, 'processing', index_col=27)\n", "\n", "# Write dataframe to local storage\n", "if not os.path.exists('data'):\n", " os.makedirs('data')\n", "\n", "# Write dataframe to csv-file\n", - "profiles.to_csv('data/profiles.csv')\n", + "#profiles.to_csv('data/profiles.csv')\n", "\n", "# Read dataframe from local storage\n", "profiles = pd.read_csv('data/profiles.csv')\n", @@ -166,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -175,23 +175,85 @@ "(244, 27)" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Clean dataframe 'profiles'\n", + "\n", "# Delete verbose and superfluous columns 6-7\n", "del profiles['Enter your SDG profile by ticking 2-4 SDGs']\n", "del profiles['One more thing!']\n", "\n", + "# Change column names\n", + "profiles = profiles.rename(columns={'The name of your fab lab':'fab-name'})\n", + "profiles = profiles.rename(columns={'Country of your fab lab':'fab-country'})\n", + "profiles = profiles.rename(columns={'URL of your fab lab page on www.fablabs.io':'fablabs.io-url'})\n", + "for s in range(17):\n", + " profiles = profiles.rename(columns={'SDG ' + str(s+1):'SDG-' + f'{(s+1):02d}'}) # SDG columns 2 digits 0 spaces\n", + "\n", + "profiles.columns = profiles.columns.str.replace(' ', '') # remove spaces in column names\n", + "profiles.columns = profiles.columns.str.lower() # convert column names to lower case\n", + "profiles.columns = profiles.columns.str.replace('sdg', 'SDG') # remove spaces in column names\n", + "\n", "profiles.shape" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<class 'pandas.core.frame.DataFrame'>\n", + "RangeIndex: 244 entries, 0 to 243\n", + "Data columns (total 27 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 slug 231 non-null object\n", + " 1 tijdstempel 238 non-null object\n", + " 2 e-mailadres 238 non-null object\n", + " 3 yourfullname 238 non-null object\n", + " 4 fab-name 238 non-null object\n", + " 5 fab-country 237 non-null object\n", + " 6 fablabs.io-url 238 non-null object\n", + " 7 SDG-01 9 non-null object\n", + " 8 SDG-02 13 non-null object\n", + " 9 SDG-03 26 non-null object\n", + " 10 SDG-04 190 non-null object\n", + " 11 SDG-05 75 non-null object\n", + " 12 SDG-06 14 non-null object\n", + " 13 SDG-07 33 non-null object\n", + " 14 SDG-08 68 non-null object\n", + " 15 SDG-09 156 non-null object\n", + " 16 SDG-10 24 non-null object\n", + " 17 SDG-11 82 non-null object\n", + " 18 SDG-12 102 non-null object\n", + " 19 SDG-13 24 non-null object\n", + " 20 SDG-14 7 non-null object\n", + " 21 SDG-15 18 non-null object\n", + " 22 SDG-16 2 non-null object\n", + " 23 SDG-17 42 non-null object\n", + " 24 summary 244 non-null object\n", + " 25 status 244 non-null object\n", + " 26 check 221 non-null object\n", + "dtypes: object(27)\n", + "memory usage: 25.8+ KB\n" + ] + } + ], + "source": [ + "profiles.info()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -200,7 +262,7 @@ "(238, 27)" ] }, - "execution_count": 7, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -208,7 +270,7 @@ "source": [ "# Clean dataframe 'profiles'\n", "# Skip empty rows\n", - "profiles = profiles.loc[profiles['Tijdstempel'].notna()]\n", + "profiles = profiles.loc[profiles['tijdstempel'].notna()]\n", "\n", "profiles.shape" ] @@ -226,16 +288,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(2015, 22)" + "(2015, 23)" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -245,18 +307,18 @@ "# Read JSON from website and convert to Dataframe\n", "url = \"https://fablabs.io/labs.json?class=btn+btn-primary\"\n", "timestamp = datetime.datetime.utcnow()\n", - "fablabs = pd.read_json(url)\n", - "fablabs = fablabs.set_index('slug')\n", + "#fablabs = pd.read_json(url)\n", + "#fablabs = fablabs.set_index('slug')\n", "\n", "# Write dataframe to local storage\n", "if not os.path.exists('data'):\n", " os.makedirs('data')\n", "\n", "# Write dataframe to csv-file\n", - "fablabs.to_csv('data/fablabs.csv')\n", + "#fablabs.to_csv('data/fablabs.csv')\n", "\n", "# Read dataframe from local storage\n", - "#fablabs = pd.read_csv('data/fablabs.csv')\n", + "fablabs = pd.read_csv('data/fablabs.csv')\n", "\n", "# log number of objects and number of fields\n", "if not os.path.exists('output'):\n", @@ -278,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -287,7 +349,7 @@ "(238, 49)" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -297,13 +359,216 @@ "profiles.shape" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create table: SDG preferences\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['slug', 'tijdstempel', 'e-mailadres', 'yourfullname', 'fab-name',\n", + " 'fab-country', 'fablabs.io-url', 'SDG-01', 'SDG-02', 'SDG-03', 'SDG-04',\n", + " 'SDG-05', 'SDG-06', 'SDG-07', 'SDG-08', 'SDG-09', 'SDG-10', 'SDG-11',\n", + " 'SDG-12', 'SDG-13', 'SDG-14', 'SDG-15', 'SDG-16', 'SDG-17', 'summary',\n", + " 'status', 'check', 'id', 'name', 'kind_name', 'parent_id', 'blurb',\n", + " 'description', 'avatar_url', 'header_url', 'address_1', 'address_2',\n", + " 'city', 'county', 'postal_code', 'country_code', 'latitude',\n", + " 'longitude', 'address_notes', 'phone', 'email', 'capabilities',\n", + " 'activity_status', 'links'],\n", + " dtype='object')" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "profiles.columns\n" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>0</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>SDG-01</th>\n", + " <td>8</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-02</th>\n", + " <td>12</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-03</th>\n", + " <td>23</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-04</th>\n", + " <td>172</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-05</th>\n", + " <td>70</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-06</th>\n", + " <td>12</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-07</th>\n", + " <td>30</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-08</th>\n", + " <td>63</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-09</th>\n", + " <td>148</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-10</th>\n", + " <td>22</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-11</th>\n", + " <td>79</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-12</th>\n", + " <td>96</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-13</th>\n", + " <td>24</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-14</th>\n", + " <td>5</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-15</th>\n", + " <td>16</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-16</th>\n", + " <td>2</td>\n", + " </tr>\n", + " <tr>\n", + " <th>SDG-17</th>\n", + " <td>35</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " 0\n", + "SDG-01 8\n", + "SDG-02 12\n", + "SDG-03 23\n", + "SDG-04 172\n", + "SDG-05 70\n", + "SDG-06 12\n", + "SDG-07 30\n", + "SDG-08 63\n", + "SDG-09 148\n", + "SDG-10 22\n", + "SDG-11 79\n", + "SDG-12 96\n", + "SDG-13 24\n", + "SDG-14 5\n", + "SDG-15 16\n", + "SDG-16 2\n", + "SDG-17 35" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# select rows with status = 'green' and columns sdg1-17\n", + "# create list of sdg column names\n", + "sdgs = []\n", + "for s in range(17):\n", + " sdgs = sdgs + [\"SDG-\" + f'{(s+1):02d}']\n", + "selprofiles = profiles[profiles['status'] == 'green'][sdgs] # select rows flagged 'green' and columns SDG1-17\n", + "selseries = selprofiles.count() # create series with sdg counts 1-17\n", + "mytable = selseries.to_frame() # convert series to frame\n", + "mytable.head(20)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<class 'pandas.core.frame.DataFrame'>\n", + "Index: 17 entries, SDG-01 to SDG-17\n", + "Data columns (total 1 columns):\n", + " # Column Non-Null Count Dtype\n", + "--- ------ -------------- -----\n", + " 0 0 17 non-null int64\n", + "dtypes: int64(1)\n", + "memory usage: 204.0+ bytes\n" + ] + } + ], + "source": [ + "seltable = selseries.to_frame()\n", + "seltable.info()\n" + ] + }, { "cell_type": "markdown", "metadata": {}, "source": [ "## State-of-affairs\n", "\n", - "* input profiles, input fablabs and merging profiles+fablabs ok " + "* current: create table with sdg preferences: SDG-code, SDG-label, Count, Percentage\n", + "* next: create piechart based on table\n", + "* next: export table and piechart as images" ] } ], diff --git a/local-workshop-sources/sdg icon translator.xlsx b/local-workshop-sources/sdg icon translator.xlsx deleted file mode 100644 index 73fb769774f18fc186ef0bb87f21cc136d77fdf6..0000000000000000000000000000000000000000 Binary files a/local-workshop-sources/sdg icon translator.xlsx and /dev/null differ diff --git a/local-workshop-sources/sdg-icon-translator.xlsx b/local-workshop-sources/sdg-icon-translator.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..6f807e745107e9e6cc616ea90e03c54e8efe6b0b Binary files /dev/null and b/local-workshop-sources/sdg-icon-translator.xlsx differ diff --git a/local-workshop-sources/sdg translator.xlsx b/local-workshop-sources/sdg-translator.xlsx similarity index 100% rename from local-workshop-sources/sdg translator.xlsx rename to local-workshop-sources/sdg-translator.xlsx