ValueError: not enough values to unpack (expected 2, got 0)

0 votes

I want to load the NSL_KDD data set in python using this link: 

https://github.com/smellslikeml/deepIDS/blob/master/deep_IDS.ipynb 

But when I run this command, attack_map = {k:v for (k,v) in attack_map} I get this error: 

ValueError: not enough values to unpack (expected 2, got 0)

 hence I’m a newbie to Python, I don’t know how to fix this error. could you anyone help me?

with open(‘G:/RUN_PYTHON/kddcup.names.txt’, ‘r’) as infile: 

kdd_names = infile.readlines() kdd_cols = [x.split(’:’)[0] for x in kdd_names[1:]]

kdd_cols += [‘class’, ‘difficulty’]

kdd = pd.read_csv(‘G:/RUN_PYTHON/KDDTrain+.txt’, names=kdd_cols) 

kdd_t = pd.read_csv(‘G:/RUN_PYTHON/KDDTest+.txt’, names=kdd_cols)

kdd_cols = [kdd.columns[0]] + sorted(list(set(kdd.protocol_type.values))) + sorted(list(set(kdd.service.values))) + sorted(list(set(kdd.flag.values))) + kdd.columns[4:].tolist()

attack_map = [x.strip().split() for x in open(‘G:/RUN_PYTHON/training_attack_types.txt’, ‘r’)] 

attack_map = {k:v for (k,v) in attack_map}

I know attack_map has empty elements. 

when I printed the attack_map, print(attack_map),

out: [[‘back’, ‘dos’], [‘buffer_overflow’, ‘u2r’], [‘ftp_write’, ‘r2l’], [‘guess_passwd’, ‘r2l’], [‘imap’, ‘r2l’], [‘ipsweep’, ‘probe’], [‘land’, ‘dos’], [‘loadmodule’, ‘u2r’], [‘multihop’, ‘r2l’], [‘neptune’, ‘dos’], [‘nmap’, ‘probe’], [‘perl’, ‘u2r’], [‘phf’, ‘r2l’], [‘pod’, ‘dos’], [‘portsweep’, ‘probe’], [‘rootkit’, ‘u2r’], [‘satan’, ‘probe’], [‘smurf’, ‘dos’], [‘spy’, ‘r2l’], [‘teardrop’, ‘dos’], [‘warezclient’, ‘r2l’], [‘warezmaster’, ‘r2l’], []]

 It has a [] element but I don’t how to can solve this problem. 

best regards

May 9 in Python by arezoo
• 220 points

edited May 13 by Gitika 2,480 views
Hey, @Arezoo,

As per your given explanation, this is happening because the attack map has an empty element []. You need to unpack the empty list into the names k and v.
@Gitika, thanks to your response

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

ValueError: too many values to unpack (expected 3)

Hello @Alisha , Do print(func(x)) and find out what's ...READ MORE

answered Aug 12 in Python by Niroj
• 58,660 points
367 views
0 votes
1 answer

How to get travis to fail if tests do not have enough coverage for python?

if you add the --fail-under switch to ...READ MORE

answered May 10, 2019 in Python by SDeb
• 13,250 points
286 views
0 votes
1 answer

How to have values from a List1 into Columns Names and List 2 Values as Index for an Empty DataFrame

Try like this, it will give you ...READ MORE

answered Jul 10, 2019 in Python by Cherukuri
• 32,490 points
205 views
+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
381 views
+1 vote
0 answers

ValueError: could not broadcast input array from shape (2) into shape (5)

I was implementing gillespie algorithm and when ...READ MORE

Dec 23, 2019 in Python by anonymous
• 130 points

reshown Jan 13 by Kalgi 1,423 views
0 votes
0 answers

How to use in python for loop not equal marks? example: a!=0

How can I in python for loop ...READ MORE

1 day ago in Python by Azizjon
• 120 points
9 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,357 views
0 votes
0 answers