Question: I have a 2-D numpy array each row of which consists of three elements - ['dataframe\_column\_name', 'dataframe\_index', 'value'].
Now, I tried populating the pandas dataframe using iloc double for loop but it is quite slow. Is there any faster way of doing this. I am a bit new to pandas, so apologies in case this is something very basic.
Here is the code snippet :

```
my_nparray = [['a', 1, 123], ['b', 1, 230], ['a', 2, 321]]
for r in range(my_nparray.shape[0]):
    [col, ind, value] = my_nparray[r]
    df.iloc[col][ind] = value

```

This takes a lot of time when my\_nparray is large, is there any other way of doing this?

Initially assume that I can create this data frame :

```
  'a' 'b'
1 NaN NaN
2 NaN NaN

```

I want the output as :

```
  'a' 'b'
1 123 230
2 321 NaN

```

Answer: 
Wouldn't this work:

```
 def convert_to_klist(map) do
   Enum.map(map, fn({key, value}) -> {String.to_existing_atom(key), value} end)
 end

```
I would put it here for the sake of future readers.

While one surely might blindly call [`String.to_atom/1`](https://hexdocs.pm/elixir/master/String.html#to_atom/1) here and there, that approach is **strongly discouraged** due to its vulnerability to atom DoS attacks.

Here is the excerpt from Erlang docs:

> 
> Atoms are not garbage-collected. Once an atom is created, it is never removed. The emulator terminates if the limit for the number of atoms (1,048,576 by default) is reached.
> 
> 
> Therefore, converting arbitrary input strings to atoms can be dangerous in a system that runs continuously. If only certain well-defined atoms are allowed as input, [`list_to_existing_atom/1`](http://erlang.org/doc/man/erlang.html#list_to_existing_atom-1) can be used to guard against a denial-of-service attack. (All atoms that are allowed must have been created earlier, for example, by simply using all of them in a module and loading that module.)
> 
> 
> — <http://erlang.org/doc/efficiency_guide/commoncaveats.html#list_to_atom-1>
> 
> 
> 

That said, whether you receive the map from the external untrusted source (e. g. it’s the parameters in the call to your API or something,) you **must not** use `String.to_atom/1` and should use [`String.to_existing_atom/1`](https://hexdocs.pm/elixir/master/String.html#to_existing_atom/1) instead.

Otherwise, the intruder with a simple random generator for keys would blow up your *ErlangVM* without any issue.