Funciones para Python
Funciones para Python
Python
Functions
For Data Professionals
*Disclaimer*
Everyone learns uniquely
1
1. NumPy - numpy.array()
About:
Syntax:
Example:
import numpy as np
my_list = [1, 2, 3, 4, 5]
my_array = np.array(my_list)
print(my_array) # Output: [1 2 3 4 5]
2
Practice Questions:
3
2. Pandas - pandas.DataFrame()
About:
Syntax:
Example:
import pandas as pd
df = pd.DataFrame(data)
print(df)
Name Age
0 John 25
1 Alice 28
2 Bob 32
4
Practice Questions:
5
3. Matplotlib -
matplotlib.pyplot.plot()
About:
Syntax:
Example:
x = [1, 2, 3, 4, 5]
y = [10, 5, 7, 8, 2]
plt.plot(x, y, marker='o')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Chart')
plt.grid(True)
plt.show()
6
Practice Questions:
7
4. Seaborn - seaborn.heatmap()
About:
Syntax:
Example:
import numpy as np
# Create a heatmap
data = np.random.rand(3, 3)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Heatmap')
plt.show()
8
Practice Questions:
9
5. Scikit-learn -
sklearn.model_selection.train_test_split()
About:
Syntax:
sklearn.model_selection.train_test_split(*arrays, test_size=None,
train_size=None, random_state=None)
Example:
from sklearn.model_selection import train_test_split
import numpy as np
X = np.arange(10).reshape((5, 2))
y = range(5)
print(X_train)
print(X_test)
10
Practice Questions:
11
6. Statsmodels -
statsmodels.api.OLS()
About:
Syntax:
statsmodels.api.OLS(endog, exog=None, missing='none', hasconst=None)
Example:
import statsmodels.api as sm
import numpy as np
X = np.array([1, 2, 3, 4, 5])
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())
12
Practice Questions:
13
7. TensorFlow -
tensorflow.keras.models.Sequential()
About:
Syntax:
tensorflow.keras.models.Sequential(layers=None, name=None)
Example:
import tensorflow as tf
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(64, activation='relu'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
print(model.summary())
14
Practice Questions:
15
8. PyTorch - torch.nn.Linear()
About:
Syntax:
Example:
import torch
layer = torch.nn.Linear(10, 5)
print(layer)
16
Practice Questions:
17
9. Datetime -
datetime.datetime.now()
About:
Syntax:
datetime.datetime.now(tz=None)
Example:
import datetime
now = datetime.datetime.now()
print(now)
18
Practice Questions:
19
10. Math - math.sqrt()
About:
Syntax:
math.sqrt(x)
Example:
import math
result = math.sqrt(16)
print(result)
20
Practice Questions:
21
11. Random - random.choice()
About:
Syntax:
random.choice(seq)
Example:
import random
random_fruit = random.choice(fruits)
print(random_fruit)
22
Practice Questions:
23
12. CSV - csv.reader()
About:
Syntax:
Example:
import csv
reader = csv.reader(file)
print(row)
24
Practice Questions:
25
13. OS - os.listdir()
About:
Syntax:
os.listdir(path='.')
Example:
import os
files = os.listdir('path/to/directory')
print(files)
26
Practice Questions:
27
Here are some sample datasets that you can
use for the practice questions:
# Practice Question
Sample Dataset:
import numpy as np
np.random.seed(0)
x = np.random.rand(100)
y = np.random.rand(100)
# Scatter plot
plt.scatter(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot')
plt.show()
28
Practice Question
Sample Dataset:
import numpy as np
# Generate x values
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.tan(x)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.show()
29
Practice Question
Sample Dataset:
import pandas as pd
import numpy as np
# Create a DataFrame
'B': np.random.rand(100),
'C': np.random.rand(100)}
df = pd.DataFrame(data)
corr_matrix = df.corr()
sns.heatmap(corr_matrix, annot=True)
plt.xlabel('Columns')
plt.ylabel('Columns')
plt.title('Correlation Heatmap')
plt.show()
30
Practice Question
Sample Dataset:
import numpy as np
X = np.random.rand(100, 3) # Features
31
Why
Bosscoder?
750+ Alumni placed at Top
Product-based companies.
Explore More