<jupyter_start><jupyter_text>Input dataset The dataset considered in this page provides the number of people migrating from one country to another. Data used comes from this [scientific publication](https://onlinelibrary.wiley.com/doi/abs/10.1111/imre.12327) already discussed on [data-to-viz.com](https://www.data-to-viz.com/graph/chord.html). The data is stored online here. Let's load it into Python as follow:<jupyter_code># Pandas is gonna be used to read the csv file stored on the web:
import pandas as pd

# Load dataset from github
data = pd.read_csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/13_AdjacencyDirectedWeighted.csv", sep=" ")
data

# Create a list of all the items in the diagram
names = data.columns.values

data = data.values.tolist()
data<jupyter_output><empty_output><jupyter_text>What's important to understand here is that the chord library used later needs a `matrix` as input.  Installing the `chord` library All the hard work is gonna be tackled by the [chord library](https://github.com/shahinrostami/chord). This library basically wraps some javascript functions available in a really powerful library called d3.js. But you do not really need to take care about this 🎉  In order to take advantage of this library, we need to use it:<jupyter_code>pip install chord<jupyter_output>Requirement already satisfied: chord in /opt/anaconda3/lib/python3.8/site-packages (0.10.0)
Note: you may need to restart the kernel to use updated packages.<jupyter_text>Most basic chord diagram Let's start with the most simple chord diagram that can be built with this library<jupyter_code># Import the library
from chord import Chord


# Basic cord diagram
# TODO THIS WON'T WORK BECAUSE INPUT TYPE ISNT RECOGNIZE
# Chord(data, names).to_html("../../static/interactiveCharts/chord-diagram-chord-library.html")
matrix = [
    [0, 5, 6, 4, 7, 4],
    [5, 0, 5, 4, 6, 5],
    [6, 5, 0, 4, 5, 5],
    [4, 4, 4, 0, 5, 5],
    [7, 6, 5, 5, 0, 4],
    [4, 5, 5, 5, 4, 0],
]


names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]

matrix
Chord(matrix, names).to_html("../../static/interactiveCharts/chord-diagram-chord-library.html")
%%html
<iframe src="../../interactiveCharts/chord-diagram-chord-library.html" width="800" height="600" title="Chord diagram with the chord library" style="border:none"></iframe><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11698584512905912, 'fraction_numerical': 0.026228143213988343, 'mean_word_length': 4.748803827751196, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '222234', 'license': '0BSD', 'n_tokens_mistral': 840, 'n_tokens_neox': 769, 'n_words': 276, 'path': 'src/notebooks/chord-diagram-python-chord.ipynb', 'repo_name': 's-lasch/The-Python-Graph-Gallery', 'size': '2402'}