Skip to content

Instantly share code, notes, and snippets.

@nickinack
Created November 20, 2020 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickinack/63714655b8900c3d96c8c59f52946f55 to your computer and use it in GitHub Desktop.
Save nickinack/63714655b8900c3d96c8c59f52946f55 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"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
},
"orig_nbformat": 2
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df1 = pd.read_csv(\"communities.data\" , header=None)\n",
"def read_header(filename):\n",
" '''\n",
" Given a filename containing headers, extract the headers and assign it to df\n",
" '''\n",
"\n",
" header_list = []\n",
" with open(filename) as f:\n",
" for line in f:\n",
" if \"@attribute\" in line:\n",
" header_list.append(line.split(\" \")[1])\n",
" return header_list\n",
" \n",
"headers = read_header(\"communities.names\")\n",
"df1.columns = headers"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment