/root/.pyenv/versions/3.11.1/lib/python3.11/site-packages/seaborn/axisgrid.py:854: FutureWarning:
`shade` is now deprecated in favor of `fill`; setting `fill=True`.
This will become an error in seaborn v0.14.0; please update your code.
func(*plot_args, **plot_kwargs)
/root/.pyenv/versions/3.11.1/lib/python3.11/site-packages/seaborn/axisgrid.py:854: FutureWarning:
`shade` is now deprecated in favor of `fill`; setting `fill=True`.
This will become an error in seaborn v0.14.0; please update your code.
func(*plot_args, **plot_kwargs)
<seaborn.axisgrid.FacetGrid at 0x7f9c6bce1f50>
/tmp/ipykernel_1400/2627332835.py:5: FutureWarning: Downcasting behavior in `replace` is deprecated and will be removed in a future version. To retain the old behavior, explicitly call `result.infer_objects(copy=False)`. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
df['Sex_num'] = df['Sex'].replace(['male','female'],[1,2])
PassengerId
Survived
Pclass
Name
Sex
Age
SibSp
Parch
Ticket
Fare
…
Age_66.0
Age_70.0
Age_70.5
Age_71.0
Age_74.0
Age_80.0
Embarked_0
Embarked_C
Embarked_Q
Embarked_S
0
1
0
3
Braund, Mr. Owen Harris
male
22.0
1
0
A/5 21171
7.2500
…
False
False
False
False
False
False
False
False
False
True
1
2
1
1
Cumings, Mrs. John Bradley (Florence Briggs Th…
female
38.0
1
0
PC 17599
71.2833
…
False
False
False
False
False
False
False
True
False
False
2
3
1
3
Heikkinen, Miss. Laina
female
26.0
0
0
STON/O2. 3101282
7.9250
…
False
False
False
False
False
False
False
False
False
True
3
4
1
1
Futrelle, Mrs. Jacques Heath (Lily May Peel)
female
35.0
1
0
113803
53.1000
…
False
False
False
False
False
False
False
False
False
True
4
5
0
3
Allen, Mr. William Henry
male
35.0
0
0
373450
8.0500
…
False
False
False
False
False
False
False
False
False
True
5 rows × 109 columns
1 2 3 4 5 6 7 8 9 10 11 12
#将类别文本转换为one-hot编码
#方法一: OneHotEncoder for feat in ["Age", "Embarked"]: x = pd.get_dummies(df["Age"] // 6) # x = pd.get_dummies(pd.cut(df['Age'],5)) x = pd.get_dummies(df[feat], prefix=feat) df = pd.concat([df, x], axis=1) #df[feat] = pd.get_dummies(df[feat], prefix=feat) df.head() df.to_csv('temp.csv')