<jupyter_start><jupyter_text>Harvard GSD  J-Term 2022  Introduction to Data Science for Building Simulation and Architectural Design***Instructor: <NAME>, <EMAIL> Date/Time: Jan 3-7/ 10:00 - 11:30 a.m. ***Pease copy this colab notebook and rename it before you start! ---  Import NumPy and pandas modulesRun the following code cell to import the NumPy and pandas modules.<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>1. Create Data Frame* to create pandas data frame from dictionary in python* to create pandas data frame from csv<jupyter_code># Create and populate a 5x2 NumPy array.
my_data = np.array([[0, 3], [10, 7], [20, 9], [30, 4], [40, 5]])

# Create a Python list that holds the names of the two columns.
my_column_names = ['temperature', 'wind speed']

# Create a DataFrame.
my_dataframe = pd.DataFrame(data=my_data, columns=my_column_names)

# Print the entire DataFrame
print(my_dataframe)
# your code here




# pandas data frame from dictionary in python
data = { "name" : ['a','b','c','d','e','f'],
         "id" : [1,3,8,10,12,60],
         "value" : [23,21,18,29,43,21]}

df = pd.DataFrame(data)

print (type(df))
print (df)

df = df.set_index("id")
print (df)
# your code here




print (df['value'])
print (df.name)
# your code here




# pandas data frames from list of list
listOfList = [[1,2,3],
             [4,5,6],
             [7,8,9]]

dfFromList = pd.DataFrame(listOfList)
print (dfFromList)


lstA = [1,2,3]
lstB = [4,5,6]
lstC = [7,8,9]
listOfList2 = []
listOfList2.append(lstA)
listOfList2.append(lstB)
listOfList2.append(lstC)

dfFromList = pd.DataFrame(listOfList2)
dfFromList.columns = ["ID", "valA", 'valB']
print (dfFromList)
# your code here<jupyter_output><empty_output><jupyter_text>2. Load dataframe<jupyter_code>from google.colab import drive
drive.mount('/content/drive')
# pandas data frame from csv
def getPandasFromFile(path, fileName, theSkipRow):
    path = os.path.join(path , fileName)
    return pd.read_csv(path, skiprows= theSkipRow , header=None, index_col = False)
def SavePandasToCSV(d, path):
    d.to_csv(path)
    return "done!!"

# modify the following file path for your GoogleDrive
FILEPATH = '/content/drive/My Drive/Colab Notebooks/J_Term/BostonWeatherFromWeb.csv'

df = pd.read_csv(FILEPATH)
df
# your code here<jupyter_output><empty_output><jupyter_text>3. index and columns, and converting data* convert data frame to list * convert data frame to numpy* convert numpy or list to data frame* manipulation columns of data frame* manipulation row of data frame<jupyter_code>print ("the index :", df.index)
print ("----------------------------------------------------")
print ("the index :", df.index.values)
print ("----------------------------------------------------")
print ('the columns', df.columns.values)
print ("----------------------------------------------------")
print (df['Average high in :'])
print (df[['Month','Days with precipitation:']])
# your codes here





# to List
airList = df['Hours of sunshine:'].tolist()
print (type(airList))
print (len(airList))
print ("------------------")
print (airList)
# your codes here





# to Numpy array
npArray = np.array(df['Hours of sunshine:'])
print (type(npArray))
print (npArray)
# your codes here





# to Pandas Data Frame
temp = df[['Month', 'Hours of sunshine:', 'Average snowfall in :']]

newNp = np.array(temp)
print (newNp)

newDF = pd.DataFrame(temp)
print (newDF)
# your codes here





# rename columns 
print (newDF.head(3))

newDF.columns = ["Time", "Sun", 'Snow']

print (newDF.head(3))
# your codes here





# get data from selected columns
dataCol = newDF['Sun'].values
print (dataCol)

dataCol = newDF['Sun']
print (dataCol)
# your codes here





# slice data between start and end index 
dataCol = newDF['Sun']

print (dataCol[2:10])
# data change by index
dataCol.iloc[6] = 0 # for 2D dataCol.iloc[:, 9]

print (dataCol[2:10])
# your codes here





print (df.describe())
print ("---------------------------------")

print ("the sum of value column :", df['Average high in :'].sum())
print ("the standard deviation of value column :", df['Average high in :'].std())
print ("the mean of value column :", df['Average high in :'].mean())
print ("the min of value column :", df['Average high in :'].min())
print ("the max of value column :", df['Average high in :'].max())
# your codes here





# sort 
sortedData = df.sort_values(['Hours of sunshine:'], ascending=[True])
sortedData
# your codes here





# conditional statement
newDF
print ("---------------------")
print (newDF['Sun'] == 0)
print ("---------------------")
print (newDF[newDF['Sun'] > 200])
print ("---------------------")
print (newDF[(newDF["Sun"] > 100) & (newDF['Sun'] < 200) ])
print ("---------------------")
print (newDF[ (newDF["Sun"] > 100) & (newDF['Snow'] > 1) ])

# your codes here<jupyter_output><empty_output><jupyter_text>4. save data* save data as csv* save data as HTML<jupyter_code># save data frame as csv
newDF.to_csv("new_data.csv", header=True)
newDF.to_html("new_data.html", header=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19702311006658832, 'fraction_numerical': 0.020368194281237758, 'mean_word_length': 3.535523978685613, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 27, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '650108', 'license': 'CC0-1.0', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1668, 'n_words': 521, 'path': 'Day0_Pandas.ipynb', 'repo_name': 'suechengsd/buildingperformance', 'size': '5126'}