{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pandas as pd\n", "import seaborn as sns\n", "import os\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 2, "outputs": [], "source": [ "agg_df = pd.DataFrame()\n", "\n", "workdir_path = 'wos_downloads/aggregated'\n", "for root, dirs, files in os.walk(workdir_path):\n", " for filename in files:\n", " if 'analyze_' in filename:\n", " path=os.path.join(root, filename)\n", " with open(os.path.join(root, 'query.txt'),'r') as f:\n", " query = f.readline()\n", " chunk = pd.read_csv(path, sep='\\t')[[\"Publication Years\",\"Record Count\"]]\n", " chunk[\"name\"] = filename.replace(\".txt\",\"\")\n", " chunk[\"query\"] = query\n", " agg_df = pd.concat([chunk,agg_df],ignore_index=True)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 3, "outputs": [], "source": [ "agg_df[\"region\"] = agg_df[\"query\"].apply(lambda x: \"EU+China\" if \"CU\" in x else \"Global\")\n", "agg_df[\"kw_token\"] = agg_df[\"query\"].apply(lambda x: x.split(\"TS=(\")[-1].split(\")\")[0])\n", "agg_df[\"kw_token\"] = agg_df[\"kw_token\"].apply(lambda x: \"OR COMPOSITE\" if \" OR \" in x else x)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 4, "outputs": [], "source": [ "agg_df = agg_df[~agg_df[\"Record Count\"].isna()]" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 5, "outputs": [ { "data": { "text/plain": " query Record Count\n0 CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST... 972.0\n1 CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST... 451.0\n2 CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST... 30.0\n3 CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST... 12.0\n4 CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST... 5.0\n.. ... ...\n384 TS=(\"word embedding*\") AND PY=(2011-2022) 7068.0\n385 TS=(\"word vector*\") AND PY=(2011-2022) 1747.0\n386 TS=((\"face recognition\" NOT \"brain\")) AND PY=(... 19690.0\n387 TS=((\"object detection\" NOT \"brain\")) AND PY=(... 28989.0\n388 TS=((\"speech recognition\" NOT \"brain\")) AND PY... 19912.0\n\n[389 rows x 2 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
queryRecord Count
0CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST...972.0
1CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST...451.0
2CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST...30.0
3CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST...12.0
4CU=(PEOPLES R CHINA OR HONG KONG) AND CU=(AUST...5.0
.........
384TS=(\"word embedding*\") AND PY=(2011-2022)7068.0
385TS=(\"word vector*\") AND PY=(2011-2022)1747.0
386TS=((\"face recognition\" NOT \"brain\")) AND PY=(...19690.0
387TS=((\"object detection\" NOT \"brain\")) AND PY=(...28989.0
388TS=((\"speech recognition\" NOT \"brain\")) AND PY...19912.0
\n

389 rows × 2 columns

\n
" }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "agg_df.groupby(\"query\",as_index=False)[\"Record Count\"].sum()" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 6, "outputs": [], "source": [ "# agg_df = agg_df[agg_df[\"Publication Years\"].str.startswith(\"20\", na=False)].copy()\n", "# agg_df[\"Publication Years\"] = agg_df[\"Publication Years\"].astype(int)\n", "# agg_df[((agg_df[\"Publication Years\"]>2010) & (agg_df[\"Publication Years\"]<2023))]" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 7, "outputs": [], "source": [ "# agg_df[\"Publication Years\"].value_counts()" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 8, "outputs": [], "source": [ "agg_df.to_excel(r'C:\\Users\\radvanyi\\PycharmProjects\\ZSI_analytics\\WOS\\wos_processed_data\\query_yearly_agg.xlsx', index=False)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 64, "outputs": [], "source": [], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }