Skip to content

Commit

Permalink
fix: error if tables empty
Browse files Browse the repository at this point in the history
  • Loading branch information
FRV-SERVICES committed Apr 25, 2024
1 parent fd82811 commit 4197199
Show file tree
Hide file tree
Showing 2 changed files with 345 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,26 +371,26 @@
" df_init[\"AUTHOR_URL\"] = tmp_df.loc[0, \"AUTHOR_URL\"]\n",
" df_init[\"ENGAGEMENTS\"] = df_init[\"LIKES\"] + df_init[\"COMMENTS\"] + df_init[\"SHARES\"]\n",
" \n",
" df_init[\"ID\"] = df_init.apply(lambda row: create_sha_256_hash(str(row[\"URL\"].split(\":activity:\")[1].split(\"/\")[0])), axis=1) \n",
" # Add KG data columns\n",
" col_ref = [\n",
" \"ID\",\n",
" \"CONCEPT\",\n",
" \"SENTIMENT\",\n",
" \"TARGET\",\n",
" \"OBJECTIVE\",\n",
" ] \n",
" for c in col_ref:\n",
" if len(df_init) == 0 and c != \"ID\":\n",
" df[c] = \"TBD\"\n",
" elif not c in df_init.columns:\n",
" df_init[c] = \"TBD\"\n",
" \n",
" if len(df_init) > 0:\n",
" # Get meta data from existing people\n",
" col_ref = [\n",
" \"ID\",\n",
" \"CONCEPT\",\n",
" \"SENTIMENT\",\n",
" \"TARGET\",\n",
" \"OBJECTIVE\",\n",
" ]\n",
" for c in col_ref:\n",
" # If columns does not exist, init value to be determined (TBD)\n",
" if not c in df_init.columns:\n",
" df_init[c] = \"TBD\"\n",
" # Merge to get meta data\n",
" ref = df_init[col_ref]\n",
" \n",
" # Merge to get meta data\n",
" df = pd.merge(df, ref, on=\"ID\", how=\"left\")\n",
" for c in col_ref:\n",
" df[c] = df[c].fillna(\"TBD\")\n",
" df = pd.merge(df, ref, on=\"ID\", how=\"left\")\n",
" for c in col_ref:\n",
" df[c] = df[c].fillna(\"TBD\")\n",
"\n",
" # Concat new posts with init\n",
" df = pd.concat([df, df_init], axis=0).reset_index(drop=True)\n",
Expand Down
Loading

0 comments on commit 4197199

Please sign in to comment.