-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandas
More file actions
48 lines (39 loc) · 1.44 KB
/
Copy pathpandas
File metadata and controls
48 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#python3 pandas, make sure csv is in the right place
import numpy as np
import pandas as pd
from matplotlib.pyplot import hist
#######################################################
matrix = np.random.randint(0,100,size=(100, 4))
print(matrix)
print(matrix[90:100,0])
random_df = pd.DataFrame(matrix, columns=list('ABCD'))
random_df['A']
random_df['A'].plot.hist()
############################################################
# generate 100 observations from random normal distribution
# with mean of 5 and SD of 2
new_col = np.random.normal(loc=5, scale=2, size=100)
# add it as a new column to our dataframe
random_df['E'] = new_col
random_df['E'].plot.hist()
#############################################################
labels = np.random.choice(['A_1', 'A_2', 'B_1', 'B_2'], size=100)
random_df['labels'] = labels
list(random_df)
################################################################33
label_group = random_df['labels'].str.split('_')
print(label_group)
random_df['group'] = label_group.str[0]
random_df.head()
########################################################
random_df.describe(include='all')
random_df.groupby('group')['A', 'B'].mean()
df_summary = random_df.groupby('group').mean()
###########################################################
mtcars = pd.read_csv('/home/cdo/mtcars.csv')
list(mtcars)
mtcars.describe()
# rename column with make and model
mtcars.rename(columns={"Unnamed: 0": 'model'}, inplace=True)
list(mtcars)
##Test!