Explore NFT Rarity by Python

Paul Anekpattanakij
Coinmonks
5 min readApr 8, 2022

--

The rarity of an NFT is determined by the frequency in which the traits and characteristics that comprise it appear within the given collection

In our example, we retrieve the NFTs list in the VOX Walking Dead Collection.

You can find the contract address of the collection by clicking on the etherscan link in Opensea.io of the selected collection. You will be redirected to Smart Contract page on etherscan.io.

NFTs collection page on Opensea.io
Smart Contract detail on etherscan.io
Read Contract Section in etherscan.io

From the contract page, you have to go to Read Contract section and find the token URI to find out the URI for each token. For this case, we can know that the URI for each token will be https://www.collectvox.com/metadata/twd/ followed by the token number, and when we open the URI, we will find that meta data file which is in the ERC-721 standard.

The rarity of each NFT will be determined by traits that each NFT has in itself. If it has a unique or rare trait, the rarity is possibly high.

Now, that we have all information that we need already, then we can start working on our Python code to explore the rarity of our NFTs.

In the example, I was working on a Python notebook in Anaconda, but please feel free to use other tools that you are comfortable with.

We got the offline data for our data exploration already. To make the code simple for the data manipulation process, we will use pandas lib which is the standard library for data engineer/data science tasks.

We will traverse all files in the folder and read them to the pandas data frame, and concatenate all data frames to be one data frame.

During the reading file, from the metadata file above, we will see that it is in the JSON format, so we can use json.loads to load it in dictionary type and we found that the traits are stored in the “attributes” as the list, then we have to normalize it first, before further processing.

Sample data from downloading to Pandas data frame with normalize attributes data

But the data will be hard to use if it is in the normalized format, then we have to transform the attribute into columns by using a pivot table.

Result from Pivot Table

We will have the table to show the relation between NFT and each possible trait in the column, and the trait name in each cell. However, we still do not know how rare it is, then we have to summarize the number of duplications of each trait and then map that number back to our data frame.

Finally, export our result to CSV file for tracking offline easily or sending to our NFT friend community.

Hooray, we have the CSV file to track our NFT rarity now, each number in the cell will show how many duplicate traits on that NFT, less number, more rarity on this NFT.

Hope you enjoy trading with information on the NFT market.

Ref : You can download notebook for this article from https://github.com/anekpattanakij/nft-rarity-finding-python

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--