Skip to content

Instantly share code, notes, and snippets.

@nickinack
Last active November 22, 2020 06:08
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/b060570ed8dcf1bf1f6d57e588ff2d53 to your computer and use it in GitHub Desktop.
Save nickinack/b060570ed8dcf1bf1f6d57e588ff2d53 to your computer and use it in GitHub Desktop.
df1 = pd.read_csv("communities.data" , header=None)
def read_header(filename):
'''
Given a filename containing headers, extract the headers and assign it to df
'''
header_list = []
with open(filename) as f:
for line in f:
if "@attribute" in line:
header_list.append(line.split(" ")[1])
return header_list
headers = read_header("communities.names")
df1.columns = headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment