<jupyter_start><jupyter_text>"Exploring 67 years of LEGO"> "DataCamp Project: Exploring 67 years of LEGO"- toc: true- branch: master- badges: true- comments: true- categories: [datacamp, projects, python]- hide: false  1. IntroductionEveryone loves Lego (unless you ever stepped on one). Did you know by the way that "Lego" was derived from the Danish phrase leg godt, which means "play well"? Unless you speak Danish, probably not. In this project, we will analyze a fascinating dataset on every single lego block that has ever been built!<jupyter_code># Nothing to do here<jupyter_output><empty_output><jupyter_text>2. Reading DataA comprehensive database of lego blocks is provided by Rebrickable. The data is available as csv files and the schema is shown below.Let us start by reading in the colors data to get a sense of the diversity of lego sets!<jupyter_code># Import modules
import pandas as pd

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

# Print the first few rows
colors.head()<jupyter_output><empty_output><jupyter_text>3. Exploring ColorsNow that we have read the colors data, we can start exploring it! Let us start by understanding the number of colors available.<jupyter_code># How many distinct colors are available?
# -- YOUR CODE FOR TASK 3 --
num_colors = len(pd.unique(colors['name']))<jupyter_output><empty_output><jupyter_text>4. Transparent Colors in Lego SetsThe colors data has a column named is_trans that indicates whether a color is transparent or not. It would be interesting to explore the distribution of transparent vs. non-transparent colors.<jupyter_code># colors_summary: Distribution of colors based on transparency
# -- YOUR CODE FOR TASK 4 --
colors_summary = colors.groupby('is_trans').count()
print(colors_summary)<jupyter_output>id  name  rgb
is_trans                
f         107   107  107
t          28    28   28<jupyter_text>5. 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
import matplotlib.pyplot as plt
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)

# Plot trends in average number of parts by year
plt.plot(parts_by_year.index, parts_by_year['num_parts'])<jupyter_output><empty_output><jupyter_text>6. 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
# -- YOUR CODE HERE --
tmp = sets[['year', 'theme_id']].groupby('year').count()
c1 = tmp.index
c2 = pd.Series(tmp['theme_id']).tolist()

themes_by_year = pd.DataFrame({'year':c1})
themes_by_year['theme_id'] = c2
print(themes_by_year)<jupyter_output>year  theme_id
0   1950         7
1   1953         4
2   1954        14
3   1955        28
4   1956        12
5   1957        21
6   1958        42
7   1959         4
8   1960         3
9   1961        17
10  1962        40
11  1963        18
12  1964        11
13  1965        10
14  1966        89
15  1967        21
16  1968        25
17  1969        69
18  1970        29
19  1971        45
20  1972        38
21  1973        68
22  1974        39
23  1975        31
24  1976        68
25  1977        92
26  1978        73
27  1979        82
28  1980        88
29  1981        79
..   ...       ...
36  1988        68
37  1989       114
38  1990        85
39  1991       106
40  1992       115
41  1993       111
42  1994       128
43  1995       128
44  1996       144
45  1997       194
46  1998       325
47  1999       300
48  2000       327
49  2001       339
50  2002       447
51  2003       415
52  2004       371
53  2005       330
54  2006       283
55  2007       319
56  2008    [...]<jupyter_text>7. Wrapping It All Up!Lego blocks offer an unlimited amount of fun across ages. We explored some interesting trends around colors, parts, and themes.<jupyter_code># Nothing to do here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06459828664042602, 'fraction_numerical': 0.10233850428339894, 'mean_word_length': 2.8640429338103757, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 28, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '133832', 'license': 'Apache-2.0', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1283, 'n_words': 560, 'path': '_notebooks/2020-01-29-Exploring-67-years-of-LEGO.ipynb', 'repo_name': 'AnuragAnalog/blog', 'size': '4319'}