-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvideo27.py
152 lines (86 loc) · 2.16 KB
/
video27.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: utf-8 -*-
"""Video27.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/17FtdKb7oe0T8KQ5obahG3Wa910ZIDMdZ
"""
import numpy as np
import pandas as pd
s = pd.Series([1,3,5,7,6.5])
s
print(type(s))
dates = pd.date_range("19980101",periods=10)
dates
df = pd.DataFrame(np.random.randn(10,4),index =dates, columns=['A','B','C','D'] )
np.random.randn(10,4)
df
from sklearn import datasets
iris = datasets.load_iris()
#iris.data
iris.feature_names
iris_df = pd.DataFrame(iris.data,index =list(range(1,151)),columns=iris.feature_names)
iris_df
d = {
"A":1.0,
"B":pd.Timestamp("20210203"),
"C":pd.Series(1,index=list(range(4)) ,dtype="float16"),
"D":np.array([3]*4, dtype="int8"),
"E":pd.Categorical(["test","train",'test',"train"]),
"F":"fff"
}
d
df2 = pd.DataFrame(d)
df2
df3 = pd.DataFrame({
"A":1.0,
"B":pd.date_range("19980101",periods=4),
"C":pd.Series(1,index=list(range(4)) ,dtype="float16"),
"D":np.array([3]*4, dtype="int16"),
"E":pd.Categorical(["test","train",'test',"train"]),
"F":"agf"
})
df3
c = pd.Categorical(["test","train",'test',"train"])
type(c)
c.add_categories("xxxxx")
df3.dtypes
iris_df.head(3) #default = 5
iris_df.tail(3)
iris_df.index
iris_df.columns
p = iris_df.to_numpy()
p
type(df3.to_numpy())
iris_df.describe()
iris.feature_names[2]
iris_df.sort_values(by = iris.feature_names[2])
iris_df.sort_index(axis=1)
plcm = iris_df['petal length (cm)']
plcm
iris.feature_names
plcm2 = iris_df[iris.feature_names[2]]
plcm2
iris_df[144:]
iris_dfc = iris_df[iris_df[iris.feature_names[2]]>5.1 ]
iris_dfc2 = iris_dfc[iris_df[iris.feature_names[3]]>1.7]
iris_dfc2
iris_df.mean()
iris_df.std()
#apply
import matplotlib.pyplot as plt
ts = pd.Series(np.random.randn(1000),index=pd.date_range("01/01/2020",periods=1000))
ts.index
ts.plot()
ts.cumsum().plot()
df = pd.DataFrame(np.random.randn(1000,4),index =ts.index, columns=['A','B','C','D'] )
df
cdf = df.cumsum()
cdf
plt.figure()
cdf.plot()
iris_df.to_csv("iris.csv")
df3
df3.to_excel("مختلط.xlsx")
fff = pd.read_csv("iris.csv")
fff.head()
?