Question: I'm taking a course on Lynda.com (Ruby on Rails 5 Essential Training) and I'm having an issue with adding a record on a table. Here's some details: The objective is to create a joint table, Many-to-Many association, so we're first trying to create a record on with of the tables we want to use on the new table. And everytime I write this line: 

```
section = Sections.create(:name => "Section One", :position => 1)

```

It gives me this

```
    (0.2ms)  BEGIN
   (0.3ms)  ROLLBACK
 => #<Section id: nil, page_id: nil, name: "Section One", position: 1, visible: false, content_type: nil, content: nil, created_at: nil, updated_at: nil> 

```

I checked my code and everything seems fine. By the way inserting records on other tables works. It's just this table. 

one important point, This table is a previously created table. It's the new one we're trying to create. 

What am I doing wrong? 

Here is my code from migrate: 

```
class CreateSections < ActiveRecord::Migration[5.2]

  def up
    create_table :sections do |t|

      t.integer   "page_id"
      t.string    "name"
      t.integer   "position"
      t.boolean   "visible", :default => false
      t.string    "content_type"
      t.text      "content"
      t.timestamps
    end
    add_index("sections", "page_id")
  end

  def down
    drop_table :sections
  end

end

```

Here is the Section model:

```
class Section < ApplicationRecord

belongs_to :page
has_many :section_edits

end

```

Answer: 
As Roland suggests, you could use `dcast()`:

```
library(data.table)
dcast(df, col_1 ~ col_2)
##   col_1   B   C   D
## 1     A 2.1 1.3 1.4
## 2     B  NA 4.6  NA

```

Where:

```
df <- data.frame(
  col_1 = c("A", "A", "B", "A"), 
  col_2 = c("B","C", "C", "D"), 
  value = c(2.1, 1.3, 4.6, 1.4)
)

```
You can do it the following way.
I write the code in Python since no language is specified

```
#I assume that your data is in a python pandas dataframe called df

df = ..load your data  
list_of_labels = [ 'A','B','C','D' ]
nb_labels = len(list_of_labels)
similarity = np.zeros( (nb_labels,nb_labels) )

for l1, l2, val in zip( df['col_1'] , df['col_2'] , df['value'] ):
    i = list_of_labels.index( l1 )
    j = list_of_labels.index( l2 )
    similarity[i][j] = val

similarity_df = pd.DataFrame(data=similarity, index=list_of_labels, columns=list_of_labels)

```