スキャッターマトリクスと色づけ
1 2 |
grr = pd.scatter_matrix(iris_dataframe,c=y_train,figsize=(15,15),marker="o", hist_kwds={"bins":20},s=60,alpha=.8,cmap=mglearn.cm3) |
スキャッターマトリクスと色づけ
1 2 |
grr = pd.scatter_matrix(iris_dataframe,c=y_train,figsize=(15,15),marker="o", hist_kwds={"bins":20},s=60,alpha=.8,cmap=mglearn.cm3) |
TypeError: unhashable type: ‘slice’
とエラーが出てデータフレームでスライスが使えない場合は以下のように
ilocを使う
1 2 3 4 5 6 7 8 |
train = pd.read_csv('train.csv', header = 0, dtype={'Age': np.float64}) test = pd.read_csv('test.csv' , header = 0, dtype={'Age': np.float64}) full_data = [train, test] dataset = pd.DataFrame(np.random.rand(10, 10))#random無くてもいける y=train.iloc[0::, 1::] X=train.iloc[0::, 0] |
1 |
train.info() |
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
PassengerId 891 non-null int64
Survived 891 non-null int64
Pclass 891 non-null int64
Name 891 non-null object
Sex 891 non-null object
Age 714 non-null float64
SibSp 891 non-null int64
Parch 891 non-null int64
Ticket 891 non-null object
Fare 891 non-null float64
Cabin 204 non-null object
Embarked 889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.6+ KB
None
選択、特定
1 2 3 4 5 6 |
df[col] # Returns column with label col as Series df[[col1, col2]] # Returns Columns as a new DataFrame s.iloc[0] # Selection by position (selects first element) s.loc[0] # Selection by index (selects element at index 0) df.iloc[0,:] # First row df.iloc[0,0] # First element of first column |
1 2 3 4 5 6 |
import numpy as np import pandas as pd iris_dataset = load_iris() print(iris_dataset["data"][:5]) |
1 2 3 4 5 |
[[ 5.1 3.5 1.4 0.2] [ 4.9 3. 1.4 0.2] [ 4.7 3.2 1.3 0.2] [ 4.6 3.1 1.5 0.2] [ 5. 3.6 1.4 0.2]] |
1 2 3 4 5 6 7 8 9 |
import pandas as pd from IPython.display import display data ={"name":["jonh","anna","peter","linda"], "location":["new york","paris","berlin","london"], "age":[24,13,53,33]} data_pandas = pd.DataFrame(data) display(data_pandas) |