0

I have a text file and want to get its values and want to put them in a dataframe in python. I know I have to use read_csv but not sure how to do it.

The text file looks something like this:

duration,protocol_type,service,flag,src_bytes,dst_bytes,land,wrong_fragment,urgent,hot,num_failed_logins,logged_in,num_compromised,root_shell,su_attempted,num_root,num_file_creations,num_shells,num_access_files,num_outbound_cmds,is_host_login,is_guest_login,count,srv_count,serror_rate,srv_serror_rate,rerror_rate,srv_rerror_rate,same_srv_rate,diff_srv_rate,srv_diff_host_rate,dst_host_count,dst_host_srv_count,dst_host_same_srv_rate,dst_host_diff_srv_rate,dst_host_same_src_port_rate,dst_host_srv_diff_host_rate,dst_host_serror_rate,dst_host_srv_serror_rate,dst_host_rerror_rate,dst_host_srv_rerror_rate 0,icmp,ecr_i,SF,1032,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,511,511,0.0,0.0,0.0,0.0,1.0,0.0,0.0,255,255,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0

Where all the strings are what I want to use for rows and the rest of them are values. I am using pandas in anaconda and the text file is called kddcup.txt. If anyone can help me out it would be much appreciated. Thank you!

rajzaveri5
  • 45
  • 2
  • 8

1 Answers1

0

Try this. Path to file is wherever your file is located, the relative path.

import pandas as pd
data = pd.read_csv('path_to_file.csv', sep=',') 
pissall
  • 7,109
  • 2
  • 25
  • 45