import pandas as pd
In [3]:
df = pd.read_csv('C:/BigData/CSV/01_data.csv')
In [4]:
df
Out[4]:
NameCountryAgeJob
0JohnUSA31Student
1SabreFrance33Lawyer
2KimKorea28Developer
3SatoJapan40Chef
4LeeKorea36Professor
5SmithUSA55CEO
6DavidUSA48Banker
In [5]:
type(df)
Out[5]:
pandas.core.frame.DataFrame
In [7]:
sr = df['Name']
In [8]:
type(sr)
Out[8]:
pandas.core.series.Series
In [10]:
df_Name = df['Name']
In [11]:
df_Name
Out[11]:
0     John
1    Sabre
2      Kim
3     Sato
4      Lee
5    Smith
6    David
Name: Name, dtype: object
In [12]:
df_Name = df[ ['Name', 'Country']]
In [13]:
df_Name
Out[13]:
NameCountry
0JohnUSA
1SabreFrance
2KimKorea
3SatoJapan
4LeeKorea
5SmithUSA
6DavidUSA
In [14]:
type(df_Name)
Out[14]:
pandas.core.frame.DataFrame
In [15]:
df.head()
Out[15]:
NameCountryAgeJob
0JohnUSA31Student
1SabreFrance33Lawyer
2KimKorea28Developer
3SatoJapan40Chef
4LeeKorea36Professor
In [26]:
df[2 : 6]['Name']
Out[26]:
2      Kim
3     Sato
4      Lee
5    Smith
Name: Name, dtype: object
In [28]:
group = df.groupby('Country')
In [29]:
group['Age'].mean()
Out[29]:
Country
France    33.000000
Japan     40.000000
Korea     32.000000
USA       44.666667
Name: Age, dtype: float64
In [30]:
df = pd.read_csv('C:/BigData/iris.csv')
In [35]:
df.shape
Out[35]:
(150, 5)
In [36]:
df.head()
Out[36]:
sepal.lengthsepal.widthpetal.lengthpetal.widthvariety
05.13.51.40.2Setosa
14.93.01.40.2Setosa
24.73.21.30.2Setosa
34.63.11.50.2Setosa
45.03.61.40.2Setosa
In [41]:
train_data = df.iloc[: , : -1]
In [43]:
train_data.head()
Out[43]:
sepal.lengthsepal.widthpetal.lengthpetal.width
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
In [44]:
train_label = df.iloc[ : , [-1]]
In [45]:
train_label
Out[45]:
variety
0Setosa
1Setosa
2Setosa
3Setosa
4Setosa
5Setosa
6Setosa
7Setosa
8Setosa
9Setosa
10Setosa
11Setosa
12Setosa
13Setosa
14Setosa
15Setosa
16Setosa
17Setosa
18Setosa
19Setosa
20Setosa
21Setosa
22Setosa
23Setosa
24Setosa
25Setosa
26Setosa
27Setosa
28Setosa
29Setosa
......
120Virginica
121Virginica
122Virginica
123Virginica
124Virginica
125Virginica
126Virginica
127Virginica
128Virginica
129Virginica
130Virginica
131Virginica
132Virginica
133Virginica
134Virginica
135Virginica
136Virginica
137Virginica
138Virginica
139Virginica
140Virginica
141Virginica
142Virginica
143Virginica
144Virginica
145Virginica
146Virginica
147Virginica
148Virginica
149Virginica

150 rows × 1 columns


+ Recent posts