I have the following list of lists:
list1=[['remote attackers',
'attacker',
'malicious code',
'malicious user',
'attack'],
['greenbone vulnerability manager',
'web application abuses',
'web management interfaces',
'application'],
['ftp servers', 'server', 'tcp', 'application', 'rpc']]
I want to cast this list of lists into a dataframe:
clusters
0 remote attackers,attacker,malicious code,malicious user,attack
1 greenbone vulnerability manager, web application abuses, web management interfaces, application
2 ftp servers,server,tcp,application,rpc
I tried to flat the list but this did not output the expected outcome.
Also, I tried to iterate over the list of lists and append each list into a dataframe but this is not working.
Any ideas?
>Solution :
Simply use the DataFrame constructor:
df = pd.DataFrame({'clusters': list1})
output:
clusters
0 [remote attackers, attacker, malicious code, m...
1 [greenbone vulnerability manager, web applicat...
2 [ftp servers, server, tcp, application, rpc]
If you want concatenated strings:
df = pd.DataFrame({'clusters': map(','.join, list1)})
output:
clusters
0 remote attackers,attacker,malicious code,malic...
1 greenbone vulnerability manager,web applicatio...
2 ftp servers,server,tcp,application,rpc