# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/a-dhingra/pandas_exercises/blob/master/05_Merge/Housing%20Market/Exercises_SolvedBySelf.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="E8uHiX2rYAIL"
# # Housing Market

# + [markdown] id="AkQclaenYAIQ"
# ### Introduction:
#
# This time we will create our own dataset with fictional numbers to describe a house market. As we are going to create random data don't try to reason of the numbers.
#
# ### Step 1. Import the necessary libraries

# + id="j5QzBZonYAIQ"
import pandas as pd
import numpy as np

# + [markdown] id="gWL2pE8qYAIR"
# ### Step 2. Create 3 differents Series, each of length 100, as follows: 
# 1. The first a random number from 1 to 4 
# 2. The second a random number from 1 to 3
# 3. The third a random number from 10,000 to 30,000

# + id="O-JW3Pt5YAIR"
s1 = pd.Series(np.random.randint(1,4,100))
s2 = pd.Series(np.random.randint(1,3,100))
s3 = pd.Series(np.random.randint(10000,30000,100))

# + id="U45WEuVZZWI-" outputId="21596bf7-ef17-4b4c-b525-efe0ef4cad91" colab={"base_uri": "https://localhost:8080/"}
s1[:5]

# + id="LtYTNMoIZZVc" outputId="0b6f0b50-9dd3-4468-c6bb-720172ce2dc1" colab={"base_uri": "https://localhost:8080/"}
s2[:10]

# + [markdown] id="hhizuWLPYAIR"
# ### Step 3. Let's create a DataFrame by joinning the Series by column

# + id="rSuzO8J0YAIR" outputId="9ded2755-9203-4657-bfbb-721726381424" colab={"base_uri": "https://localhost:8080/", "height": 202}
df = pd.concat([s1,s2,s3], axis=1 ) # axis=1 means columns
df.head()

# + [markdown] id="W1JruiUOYAIS"
# ### Step 4. Change the name of the columns to bedrs, bathrs, price_sqr_meter

# + id="0kn-VXYwYAIS" outputId="7a7cf55d-2b78-49ab-f953-d52641428941" colab={"base_uri": "https://localhost:8080/", "height": 202}
df = df.rename(columns={0:'bedrs',1:'bathrs',2:'price_sqr_meter'})
df.head()

# + [markdown] id="kvDpGUC6YAIS"
# ### Step 5. Create a one column DataFrame with the values of the 3 Series and assign it to 'bigcolumn'

# + id="NEYrZsbhYAIS" outputId="4e2576d3-a735-4c95-b13b-d84a29f1df3d" colab={"base_uri": "https://localhost:8080/", "height": 662}
bigcolumn = pd.concat([s1,s2,s3], axis=0)
# bigcolumn.shape
bigcolumn = bigcolumn.to_frame()
bigcolumn.tail(20)

# + [markdown] id="IYp5qdEkYAIS"
# ### Step 6. Oops, it seems it is going only until index 99. Is it true?

# + id="eDe77WJ6YAIT" outputId="54226734-bab3-4fe7-d086-c4e204bd24be" colab={"base_uri": "https://localhost:8080/", "height": 202}
bigcolumn.tail()

# + [markdown] id="PHygdjkEYAIT"
# ### Step 7. Reindex the DataFrame so it goes from 0 to 299

# + id="1LaOC759YAIT" outputId="4cd11d23-6832-4aff-9de6-89ae7b302c89" colab={"base_uri": "https://localhost:8080/", "height": 202}
bigcolumn.reset_index(drop=True, inplace=True)
bigcolumn.tail()

# + id="_Nvv3qtXa85g"


StarcoderdataJupyterScriptsDedupFiltered