1
0
govdoc-cr-analysis/text_analysis/contributing_partitioned_analysis.ipynb

294 lines
8.3 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"merged_manifest = pd.read_csv('0203_contributing_merged_manifest.csv')\n",
"topic_distributions = pd.read_csv('020125_CONTRIBUTING_file_topic_distributions.csv')\n",
"readability_scores = pd.read_csv('020125_CONTRIBUTING_readability.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"715"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"first_merge = readability_scores.merge(topic_distributions, on=['filename'],how=\"inner\")\n",
"#primary_merge = first_merge.merge(readability_scores, )\n",
"first_merge['fvf_filepath'] = first_merge['filename']\n",
"second_merge = first_merge.merge(merged_manifest, on=['fvf_filepath'], how=\"inner\")\n",
"len(second_merge)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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 tr th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe thead tr:last-of-type th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr>\n",
" <th></th>\n",
" <th colspan=\"2\" halign=\"left\">flesch_reading_ease</th>\n",
" <th colspan=\"2\" halign=\"left\">reading_time</th>\n",
" <th colspan=\"2\" halign=\"left\">word_count</th>\n",
" </tr>\n",
" <tr>\n",
" <th></th>\n",
" <th>mean</th>\n",
" <th>median</th>\n",
" <th>mean</th>\n",
" <th>median</th>\n",
" <th>mean</th>\n",
" <th>median</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ranef_grouping</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>46.102071</td>\n",
" <td>49.99</td>\n",
" <td>23.409286</td>\n",
" <td>13.720</td>\n",
" <td>259.635714</td>\n",
" <td>153.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>44.237276</td>\n",
" <td>53.41</td>\n",
" <td>29.065789</td>\n",
" <td>16.880</td>\n",
" <td>329.151703</td>\n",
" <td>198.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>47.432222</td>\n",
" <td>54.78</td>\n",
" <td>34.361627</td>\n",
" <td>23.365</td>\n",
" <td>394.242063</td>\n",
" <td>252.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" flesch_reading_ease reading_time word_count \\\n",
" mean median mean median mean \n",
"ranef_grouping \n",
"0 46.102071 49.99 23.409286 13.720 259.635714 \n",
"1 44.237276 53.41 29.065789 16.880 329.151703 \n",
"2 47.432222 54.78 34.361627 23.365 394.242063 \n",
"\n",
" \n",
" median \n",
"ranef_grouping \n",
"0 153.0 \n",
"1 198.0 \n",
"2 252.0 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"readability_aggregate = second_merge.groupby('ranef_grouping').agg({\n",
" 'flesch_reading_ease' : ['mean', 'median'],\n",
" 'reading_time' : ['mean', 'median'],\n",
" 'word_count' : ['mean', 'median'],\n",
"})\n",
"\n",
"readability_aggregate"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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 tr th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe thead tr:last-of-type th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr>\n",
" <th></th>\n",
" <th>t0</th>\n",
" <th>t1</th>\n",
" <th>t2</th>\n",
" <th>t3</th>\n",
" <th>t4</th>\n",
" </tr>\n",
" <tr>\n",
" <th></th>\n",
" <th>mean</th>\n",
" <th>mean</th>\n",
" <th>mean</th>\n",
" <th>mean</th>\n",
" <th>mean</th>\n",
" </tr>\n",
" <tr>\n",
" <th>ranef_grouping</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.093281</td>\n",
" <td>0.368268</td>\n",
" <td>0.156304</td>\n",
" <td>0.098748</td>\n",
" <td>0.283398</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.157519</td>\n",
" <td>0.281908</td>\n",
" <td>0.185817</td>\n",
" <td>0.112195</td>\n",
" <td>0.262561</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.202565</td>\n",
" <td>0.252555</td>\n",
" <td>0.167163</td>\n",
" <td>0.090678</td>\n",
" <td>0.287039</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" t0 t1 t2 t3 t4\n",
" mean mean mean mean mean\n",
"ranef_grouping \n",
"0 0.093281 0.368268 0.156304 0.098748 0.283398\n",
"1 0.157519 0.281908 0.185817 0.112195 0.262561\n",
"2 0.202565 0.252555 0.167163 0.090678 0.287039"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"topic_aggregate = second_merge.groupby('ranef_grouping').agg({\n",
" 't0' : ['mean'],\n",
" 't1' : ['mean'],\n",
" 't2' : ['mean'],\n",
" 't3' : ['mean'],\n",
" 't4' : ['mean']\n",
"})\n",
"\n",
"topic_aggregate"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}