Pandas : how to add Column name on dataframe on csv file

Viewed 5070

new but excited about Python and i need your advice. I came up with the following code to compare two CSV files based on nmap scan:

import pandas as pd
from pandas import DataFrame
import os
file = raw_input('\nEnter the Old CSV file: ')
file1 = raw_input('\nEnter the New CSV file: ')
A=set(pd.read_csv(file, index_col=False, header=None)[0])
B=set(pd.read_csv(file1, index_col=False, header=None)[0])
final=list(A-B)
df = pd.DataFrame(final, columns=["host"])
df.to_csv('DIFF_'+file)

print "Completed!"

when i run it i got the following results: ,

host
0,82.214.228.71;dsl-radius-02.direcpceu.com;PTR;tcp;111;rpcbind;open;;;syn-ack;;3;
1,82.214.228.70;dsl-radius-01.direcpceu.com;PTR;tcp;111;rpcbind;open;;;syn-ack;;3;

My question is how to add a label/enter code herename on the columns 2,3 etc for example: hostanme , port , port name ,state etc. I have tried : df['hostname'] = range(1, len(df) + 1) but this adds the hostname on the first column along with host when i open the file with Excel

2 Answers
Related