<jupyter_start><jupyter_text>Playing with Lego Data from RebrickableAh, the good old childhood days of playing with your Lego sets. I went down this memory lane last week when I visited a bookstore and found a Lego play area. I added bricks to someone else’s tower and built a car next to it. opensource ftwFun fact: “Lego” was derived from the Danish phrase leg godt, which means “play well”.In this analysis, I explore the colors of the bricks and the different parts and themes of the sets.  About the DataA comprehensive database of lego blocks is provided by Rebrickable. The data is available as csv files and the schema is shown below.  Getting a sense of the diversity of Lego sets! First 5 rows of colors data<jupyter_code># Import pandas
import pandas as pd

# Read colors data
colors = pd.read_csv("datasets/colors.csv")

# Print the first few rows
print(colors.head())<jupyter_output>id            name     rgb is_trans
0  -1         Unknown  0033B2        f
1   0           Black  05131D        f
2   1            Blue  0055BF        f
3   2           Green  237841        f
4   3  Dark Turquoise  008F9B        f<jupyter_text>How many distinct colors of bricks are available?<jupyter_code># How many distinct colors are available?
num_colors = len(colors.index)

# Print num_colors
print(str(num_colors)+ " colors")<jupyter_output>135 colors<jupyter_text>Transparent Colors in Lego Sets The colors data has a column named is_trans that indicates whether a color is transparent (t) or not (f). Exploring the distribution of transparent vs. non-transparent colors.<jupyter_code># colors_summary: Distribution of colors based on transparency
colors_summary = colors.groupby('is_trans').agg('count')
print(colors_summary)<jupyter_output>id  name  rgb
is_trans                
f         107   107  107
t          28    28   28<jupyter_text>Explore Lego SetsAnother interesting dataset available in this database is the sets data. It contains a comprehensive list of sets over the years and the number of parts that each of these sets contained.Let us use this data to explore how the average number of parts in Lego sets has varied over the years.<jupyter_code>%matplotlib inline
# Read sets data as `sets`
sets = pd.read_csv('datasets/sets.csv')

# Create a summary of average number of parts by year: `parts_by_year`
parts_by_year = sets[['year', 'num_parts']].groupby('year').mean()
print(parts_by_year.head())

# Plot trends in average number of parts by year
parts_by_year.plot()<jupyter_output>num_parts
year           
1950  10.142857
1953  16.500000
1954  12.357143
1955  36.857143
1956  18.500000<jupyter_text>Lego Themes Over YearsLego blocks ship under multiple themes. Let us try to get a sense of how the number of themes shipped has varied over the years.<jupyter_code># themes_by_year: Number of themes shipped by year
themes_by_year = sets[['year', 'theme_id']].groupby('year').nunique()
print(themes_by_year)<jupyter_output>theme_id
year          
1950         2
1953         1
1954         2
1955         4
1956         3
...        ...
2013        93
2014        92
2015        99
2016        88
2017        78

[66 rows x 1 columns]<jupyter_text>Ending with Star WarsStar Wars: The Phantom Menace was released in 1999. We saw Lego coming out with Star Wars special edition that became a huge success. Let's take a closer look at the themes_by_year to study the number of unique themes that Lego released in 1999<jupyter_code># Get the number of unique themes released in 1999
num_themes = themes_by_year.loc[1999,'theme_id']

# Print the number of unique themes released in 1999
print(str(num_themes)+" themes released in 1999")<jupyter_output>71 themes released in 1999
{'fraction_non_alphanumeric': 0.0575831305758313, 'fraction_numerical': 0.054339010543390104, 'mean_word_length': 3.5905707196029777, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '264668', 'license': 'MIT', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1057, 'n_words': 478, 'path': 'product-lego/lego.ipynb', 'repo_name': 'anilgeorge04/eda-notes', 'size': '3699'}