<jupyter_start><jupyter_text>Very Brief Intro to Python  This is a notebook for very brief intro to Python. There is also a notebook to learn more, you may want to check [here](https://colab.research.google.com/github/yohanesnuwara/python-bootcamp-for-geoengineers/blob/master/petroweek_notebooks/petroweek2020_unit1.ipynb). To open these notebooks in Colab, click "Copy to Drive", then you'll have this notebook and freely code. Happy learning!   Using libraries<jupyter_code># import libraries. These one have been pre-installed.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# this is style for plotting. There are many, you can try: 'classic', 'seaborn'
# but if you don't want any style, you can just omit this code. 
plt.style.use('ggplot')<jupyter_output><empty_output><jupyter_text>Very Brief Intro to Numpy<jupyter_code># generate array from 0 to 10 into 100 numbers
a = np.linspace(0, 10, 100)
print(a)
# generate array from 0 to 10 with increment of 0.25
b = np.arange(0, 10, 0.25)
print(b)
# generate 100 uniform random numbers from 0 to 1
c = np.random.random(100)
print(c)
# multiplying a and c arrays
print(a * c)
# make a function y=f(x), b as input
def cubic(x, a, b, c):
  y = a* (x**3) + b * (x**2) + c * x
  return y

y = cubic(b, 0.5, 0.25, 0.75)
print(y)
# make a 2D array and transpose it
d = np.array([[1,2,3,4,5],
              [6,7,8,9,10],
              [11,12,13,14,15]])
d_trans = d.T
print(d)
print(d_trans)<jupyter_output>[[ 1  2  3  4  5]
 [ 6  7  8  9 10]
 [11 12 13 14 15]]
[[ 1  6 11]
 [ 2  7 12]
 [ 3  8 13]
 [ 4  9 14]
 [ 5 10 15]]<jupyter_text>Very Brief Intro to Matplotlib<jupyter_code># make a trigonometric array
x = np.linspace(0,360,100)
xrad = np.deg2rad(x)

y1 = np.sin(xrad)
y2 = np.cos(xrad)

# plot this function
plt.plot(xrad, y1)
plt.plot(xrad, y2)
plt.title('Trigonometric Function', size=20, pad=10)
plt.xlabel('X')
plt.ylabel('Y')
# plt.xlim(min(x), max(x))

plt.show()<jupyter_output><empty_output><jupyter_text>Very Brief Intro to Pandas<jupyter_code># convert the trigonometry result into a dataframe (a.k.a spreadsheet)
trig = pd.DataFrame({'X': x, 'sin(x)': y1, 'cos(x)': y2})

# print it
trig
# print the first 10 rows 
trig.head(10)
# print the last 10 rows
trig.tail(10)
# create another dataframe 
names = ['Robby', 'Alice', 'Rick', 'James', 'Alley']
ages = [20, 30, 21, 17, 18]
cars = [0, 2, 3, 1, 6]

data = pd.DataFrame({'Name': names, 'Age': ages, 'Cars': cars})

data
# add new columns "hometown" and "gender" to our data
hometown = ['Berlin', 'Madras', 'London', 'Warsaw', 'Paris']
gender = ['Male', 'Female', 'Male', 'Male', 'Female']

data['Hometown'] = hometown
data['Gender'] = gender

data
# print only the data with "Name" column
data['Name']
# or another alternative
data.iloc[:,0]
# print only the data in the first row
data.iloc[1,:]
# print only the data with "Gender" as "Female"
mask_male = data['Gender'] == 'Female'

data[mask_male]<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup