利用 Numpy、Pandas 分析泰坦尼克沉船数据
itomcoil 2025-09-18 01:23 2 浏览
这次采用Python语言平台里的numpy和pandas两个常用的数据处理和分析的包来再次分析泰坦尼克沉船数据。
导入开发包
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
从文件导入数据
df = pd.read_csv('/home/frank/mydata/Datasets/train.csv')
df
查看数据表的字段
df.columns
Index(['PassengerId', 'Survived', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp', 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'], dtype='object')
将所有字段变为小写
为了后续书写的方便,把所有的特征名称都改为小写
df.columns = df.columns.str.lower()
创建新的dataframe,去掉一些对数据分析无用的字段
有些特征对数据分析没有什么帮助,为了让数据更加整洁,在有些场景下也是为了规避隐私问题,将一些特征去掉,得到一个更加紧凑的dataframe类型的对象。这里是通过直接从原始的dataframe里把需要的特征列取出来,赋值给新的dataframe。
titanic_df = df[[
'survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare', 'cabin',
'embarked'
]]
可以再查看得到的dataframe有哪些特征
Index(['survived', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare', 'cabin', 'embarked'], dtype='object')
统计遇难、生还的人数,以及总人数
survived_passenger_num = len(titanic_df[titanic_df['survived'] == 1])
print('共有 ' + str(survived_passenger_num) + ' 人生还')
dead_passenger_num = len(titanic_df[titanic_df['survived'] == 0])
print('共有 ' + str(dead_passenger_num) + ' 人遇难')
total_passenger = len(titanic_df)
print('共有 ' + str(total_passenger) + ' 名乘客')
共有 342 人生还
共有 549 人遇难
共有 891 名乘客
数据可视化:用饼图展示乘客生还和遇难的比例
import seaborn as sns
sns.set_context('talk')
labels = 'Survived', 'Dead'
values = [survived_passenger_num, dead_passenger_num]
fig, ax = plt.subplots(figsize=(12, 8))
ax.pie(values,
labels=labels,
autopct='%1.2f%%',
startangle=90,
shadow=True,
labeldistance=1.2,
textprops={
'fontsize': 18,
'color': 'w'
})
ax.axis('equal')
plt.title('Titanic Passenger Survived or Dead', color='w')
plt.legend(loc='upper right')
plt.show()
数据可视化:用柱状图展示乘客生还和遇难的情况
import seaborn as sns
sns.set_context('talk')
labels = 'Survived', 'Dead'
values = [survived_passenger_num, dead_passenger_num]
fig, ax = plt.subplots(figsize=(9, 6))
ba = ax.bar(labels, values, label='passenger', width=0.4)
ax.set_title('Titanic Passenger Survived and Dead', color='w', pad=15)
ax.legend()
ax.set_xlabel('survived or dead', color='w')
ax.set_ylabel('Number of Passengers', color='w')
ax.set_axisbelow(True)
ax.yaxis.grid(True, color='#EEEEEE')
ax.xaxis.grid(False)
ax.bar_label(ba)
plt.xticks(color='w')
plt.yticks(color='w')
plt.show()
按照船舱的档次进行统计
去掉重复的数据,可以看出船舱有 1,2,3 三个档次
titanic_df['pclass'].drop_duplicates()
0 3
1 1
9 2
Name: pclass, dtype: int64
三个档次的船舱的乘客数
pclass_1_count = len(titanic_df[titanic_df['pclass'] == 1])
pclass_2_count = len(titanic_df[titanic_df['pclass'] == 2])
pclass_3_count = len(titanic_df[titanic_df['pclass'] == 3])
print('一等舱乘客数:' + str(pclass_1_count))
print('二等舱乘客数:' + str(pclass_2_count))
print('三等舱乘客数:' + str(pclass_3_count))
一等舱乘客数:216
二等舱乘客数:184
三等舱乘客数:491
三个档次的船舱里生还的乘客数
pclass_1_survived_count = len(
titanic_df.loc[
(titanic_df['pclass'] == 1)
&
(titanic_df['survived'] == 1)
]
)
pclass_2_survived_count = len(
titanic_df.loc[
(titanic_df['pclass'] == 2)
&
(titanic_df['survived'] == 1)
]
)
pclass_3_survived_count = len(
titanic_df.loc[
(titanic_df['pclass'] == 3)
&
(titanic_df['survived'] == 1)
]
)
print('一等舱乘客数:' + str(pclass_1_count)+', 其中生还人数为 '+str(pclass_1_survived_count))
print('二等舱乘客数:' + str(pclass_2_count)+', 其中生还人数为 '+str(pclass_2_survived_count))
print('三等舱乘客数:' + str(pclass_3_count)+', 其中生还人数为 '+str(pclass_3_survived_count))
一等舱乘客数:216, 其中生还人数为 136
二等舱乘客数:184, 其中生还人数为 87
三等舱乘客数:491, 其中生还人数为 119
不同船舱生还乘客占总生还乘客的比例
total_survived_count = len(
titanic_df[titanic_df['survived'] == 1]
)
pclass1_survived_percentage = round(
pclass_1_survived_count/total_survived_count*100,
2
)
pclass2_survived_percentage = round(
pclass_2_survived_count/total_survived_count*100,
2
)
pclass3_survived_percentage = round(
pclass_3_survived_count/total_survived_count*100,
2
)
print('一等舱生还人数占总生还人数的比例为:'+str(pclass1_survived_percentage)+'%')
print('二等舱生还人数占总生还人数的比例为:'+str(pclass2_survived_percentage)+'%')
print('三等舱生还人数占总生还人数的比例为:'+str(pclass3_survived_percentage)+'%')
利用round函数得到小数位经过规整后的百分数。
一等舱生还人数占总生还人数的比例为:39.77%
二等舱生还人数占总生还人数的比例为:25.44%
三等舱生还人数占总生还人数的比例为:34.8%
通过性别进行统计分析
统计乘客中的性别分布
male_count = len(titanic_df[titanic_df['sex'] == 'male'])
female_count = len(titanic_df[titanic_df['sex'] == 'female'])
print('男性乘客 '+str(male_count)+' 人')
print('女性乘客 '+str(female_count)+' 人')
男性乘客 577 人
女性乘客 314 人
在生还的乘客中统计性别分布
male_survived_count = len(
titanic_df.loc[
(titanic_df['sex'] == 'male')
&
(titanic_df['survived'] == 1)
]
)
female_survived_count = len(
titanic_df.loc[
(titanic_df['sex'] == 'female')
&
(titanic_df['survived'] == 1)
]
)
print(
'男性乘客 '+str(male_count)+' 人, 其中生还者 '
+ str(male_survived_count)+' 人'
)
print(
'女性乘客 '+str(female_count)+' 人, 其中生还者 '
+ str(female_survived_count)+' 人'
)
男性乘客 577 人, 其中生还者 109 人
女性乘客 314 人, 其中生还者 233 人
代码可视化:用柱状图展示乘客的性别数据以及在不同性别中的生还人数
# Use seaborn's context settings to make fonts larger
import seaborn as sns
sns.set_context('talk')
# make data by array
labels = ['Male', 'Female']
sex_survived_list = [male_survived_count, female_survived_count]
sex_list = [male_count, female_count]
fig, ax = plt.subplots(figsize=(12, 8))
x = np.arange(len(labels))
bar_width = 0.25
b1 = ax.bar(x-bar_width/2, sex_survived_list, width=bar_width)
b2 = ax.bar(x+bar_width/2, sex_list, width=bar_width)
ax.legend(['Survived', 'Total'])
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.set_axisbelow(True)
ax.yaxis.grid(True, color='#EEEEEE')
ax.xaxis.grid(False)
ax.set_title('Passengers with Survived', pad=15, color='w')
ax.set_xlabel('Gender', labelpad=15, color='w')
ax.set_ylabel('Number of Passengers', color='w')
ax.bar_label(b1, padding=3)
ax.bar_label(b2, padding=3)
plt.xticks(color='w')
plt.yticks(color='w')
fig.tight_layout()
plt.show()
通过年龄进行统计分析
len(titanic_df[titanic_df['age'].isnull()])
177
数据集中共有177行中的age字段的值为空,接下来考虑用现有的age的平均数来填充这些空缺的值。
计算 age 的平均数。从年龄大于0的行中,取出所有的age数据,计算这些数据的平均数。然后保留一位小数。
avg_age = round(titanic_df[titanic_df['age'] > 0]['age'].mean(), 1)
avg_age
29.7
用这个平均数填补到age为空值的地方
titanic_df['age'].fillna(avg_age, inplace=True)
再次查看年龄属性,没有了空值。值为 null 的位置已经用平均年龄值做了填充
len(titanic_df[titanic_df['age'].isnull()])
0
按照年龄段进行统计
这里将年龄段划分为 0 ~ 11(儿童),12 ~ 17(少年),18 ~ 64(成年),65 以上(老年)
children_count = len(titanic_df[
(titanic_df['age'] > 0)
&
(titanic_df['age'] < 12)
])
juvenile_count = len(titanic_df[
(titanic_df['age'] >= 12)
&
(titanic_df['age'] < 18)
])
audit_count = len(titanic_df[
(titanic_df['age'] >= 18)
&
(titanic_df['age'] < 65)
])
old_count = len(titanic_df[
(titanic_df['age'] >= 65)
])
print('乘客中儿童人数:'+str(children_count)+' 人')
print('乘客中少年人数:'+str(juvenile_count)+' 人')
print('乘客中成年人数:'+str(audit_count)+' 人')
print('乘客中老年人数:'+str(old_count)+' 人')
乘客中儿童人数:68 人
乘客中少年人数:45 人
乘客中成年人数:767 人
乘客中老年人数:11 人
数据可视化:统计所有乘客的年龄分布
用柱状图展示人数,用饼图展示人数的比例分布,将两个图形放在一个画布中
import seaborn as sns
sns.set_context('talk')
labels = 'children', 'juvenile', 'audit', 'old'
values = [children_count, juvenile_count, audit_count, old_count]
fig, ax = plt.subplots(1, 2, figsize=(12, 6), dpi=80)
# 年龄分布的柱状图
ba = ax[0].bar(labels, values, label='passenger', width=0.4)
ax[0].set_title('Age distribution', color='w', pad=20)
ax[0].set_xlabel('Type of passenger', color='w', labelpad=20)
ax[0].set_ylabel('Num of Passenger', color='w', labelpad=20)
ax[0].set_axisbelow(True)
ax[0].yaxis.grid(True, color='#EEEEEE')
ax[0].xaxis.grid(False)
ax[0].tick_params(colors="w")
ax[0].bar_label(ba, padding=3)
# 年龄分布的饼图
ax[1].pie(values,
labels=labels,
autopct='%1.0f%%',
startangle=0,
shadow=True,
labeldistance=1.1,
textprops={
'fontsize': 14,
'color': 'w'
})
ax[1].axis('equal')
ax[1].set_title('Age distribution', color='w', pad=10)
ax[1].legend(loc='upper left')
按照年龄统计生还乘客的数据
children_survived_count = len(titanic_df[
(titanic_df['age'] > 0)
&
(titanic_df['age'] < 12)
&
(titanic_df['survived'] == 1)
])
juvenile_survived_count = len(titanic_df[
(titanic_df['age'] >= 12)
&
(titanic_df['age'] < 18)
&
(titanic_df['survived'] == 1)
])
audit_survived_count = len(titanic_df[
(titanic_df['age'] >= 18)
&
(titanic_df['age'] < 65)
&
(titanic_df['survived'] == 1)
])
old_survived_count = len(titanic_df[
(titanic_df['age'] >= 65)
&
(titanic_df['survived'] == 1)
])
print('乘客中[儿童]人数:'+str(children_count)+' 人,生还 ' +
str(children_survived_count)+' 人')
print('乘客中[少年]人数:'+str(juvenile_count)+' 人,生还 ' +
str(juvenile_survived_count)+' 人')
print('乘客中[成年]人数:'+str(audit_count)+' 人,生还 ' + str(audit_survived_count)+' 人')
print('乘客中[老年]人数:'+str(old_count)+' 人,生还 ' + str(old_survived_count)+' 人')
乘客中[儿童]人数:68 人,生还 39 人
乘客中[少年]人数:45 人,生还 22 人
乘客中[成年]人数:767 人,生还 280 人
乘客中[老年]人数:11 人,生还 1 人
数据可视化:用饼图展示生还人数的年龄分布
import seaborn as sns
sns.set_context('talk')
labels = 'children', 'juvenile', 'audit', 'old'
values = [children_survived_count, juvenile_survived_count,
audit_survived_count, old_survived_count]
fig, ax = plt.subplots(figsize=(12, 8))
ax.pie(values,
labels=labels,
autopct='%1.2f%%',
startangle=0,
shadow=True,
labeldistance=1.2,
textprops={
'fontsize': 18,
'color': 'w'
})
ax.axis('equal')
plt.title('Survived Passengers Percentage', color='w')
plt.legend(loc='upper left')
plt.show()
通过乘客的兄弟姐妹数据统计生还率
len(titanic_df[titanic_df['sibsp'].isnull()])
0
sibsp 这一列没有空值
新添加一列 havesibsp,用于表明是否有兄弟姐妹。默认值为 0
titanic_df['havesibsp'] = 0
如果有兄弟姐妹(sibsp 的值不为 0),则 havesibsp 的值为 1,否则为 0
loc 函数内部的第一个参数是筛选行的条件,第二个参数是要修改的列。
等号后面的值是如果满足筛选条件,给要修改的列赋的新值
titanic_df.loc[titanic_df['sibsp'] > 0, 'havesibsp'] = 1
统计有兄弟姐妹的乘客中生还的人数以及生还率
havesibsp_survived_count = len(
titanic_df[
(titanic_df['havesibsp'] == 1)
&
(titanic_df['survived'] == 1)
]
)
havesibsp_survived_count
132
print(
'在 '+str(total_survived_count) +
' 位生还乘客中,有兄弟姐妹的人数为 ' +
str(havesibsp_survived_count)+' 人, 比率为 ' +
str(
round(
havesibsp_survived_count / total_survived_count * 100, 1)
) + ' %'
)
在 342 位生还乘客中,有兄弟姐妹的人数为 132 人, 比率为 38.6 %
将上面的代码里的筛选条件修改为这样的形式,【 titanic_df['havesibsp'] == 0】,那就是在统计没有兄弟姐妹的乘客的生还情况,具体操作这里略去。
通过乘客的父母子女数据统计生还率
这里的操作和上面通过兄弟姐妹的人数统计的过程很类似,首先查看parch这个字段是否有空值,如果有则填补上平均数;然后新建一个新的列用于标注是否有父母子女,如果有则该列的值为1,否则为0;最后进行计算统计。
查看父母子女数据中是否有空值
len(titanic_df[titanic_df['parch'].isnull()])
0
新添加一列 haveparch 表示是否有父母子女,默认值为 0
titanic_df['haveparch'] = 0
如果有父母子女(parch 的值不为 0),则 haveparch 的值为 1,否则为 0
loc 函数内部的第一个参数是筛选行的条件,第二个参数是要修改的列。
等号后面的值是如果满足筛选条件,给要修改的列赋的新值
titanic_df.loc[titanic_df['parch'] > 0, 'haveparch'] = 1
haveparch_survived_count = len(
titanic_df[
(titanic_df['haveparch'] == 1)
&
(titanic_df['survived'] == 1)
]
)
haveparch_survived_count
noparch_survived_count = len(
titanic_df[
(titanic_df['haveparch'] == 0)
&
(titanic_df['survived'] == 1)
]
)
noparch_survived_count
print(
'在 ' + str(total_survived_count) + ' 位生还者中\n\n有父母子女的乘客为 ' +
str(haveparch_survived_count)+' 人, 比率为 ' +
str(round(haveparch_survived_count/total_survived_count*100, 1)) + '%'
+ '\n无父母子女的乘客为 ' + str(noparch_survived_count)+' 人, 比率为 ' +
str(round(noparch_survived_count/total_survived_count*100, 1))+'%'
)
在 342 位生还者中
有父母子女的乘客为 109 人, 比率为 31.9%
无父母子女的乘客为 233 人, 比率为 68.1%
通过票价数据进行统计和分析
票价数据没有空值
len(titanic_df[titanic_df['fare'].isnull()])
0
计算票价的最高、最低、平均值
print('票价最高值:$ '+str(max(titanic_df['fare'])))
print('票价最低值:$ '+str(min(titanic_df['fare'])))
avg_fare = round(titanic_df['fare'].mean(), 2)
print('票价平均值:$ '+str(avg_fare))
票价最高值:$ 512.3292
票价最低值:$ 0.0
票价平均值:$ 32.2
统计生还者的票价分布
票价档位:一档 0~99, 二档 100~299,三档300~499,四档 500+
统计票价在不同档位的乘客中生还乘客的个数
fare_first_range_survived_count = len(
titanic_df.loc[
(titanic_df['fare'] >= 0)
&
(titanic_df['fare'] < 100)
&
(titanic_df['survived'] == 1)
]
)
fare_second_range_survived_count = len(
titanic_df.loc[
(titanic_df['fare'] >= 100)
&
(titanic_df['fare'] < 300)
&
(titanic_df['survived'] == 1)
]
)
fare_third_range_survived_count = len(
titanic_df.loc[
(titanic_df['fare'] >= 300)
&
(titanic_df['fare'] < 500)
&
(titanic_df['survived'] == 1)
]
)
fare_fourth_range_survived_count = len(
titanic_df.loc[
(titanic_df['fare'] >= 500)
&
(titanic_df['survived'] == 1)
]
)
print('在生还的乘客中:\n')
print('一档票价的人数:'+str(fare_first_range_survived_count)+'\t')
print('一档票价的人数:'+str(fare_second_range_survived_count)+'\t')
print('一档票价的人数:'+str(fare_third_range_survived_count)+'\t')
print('一档票价的人数:'+str(fare_fourth_range_survived_count)+'\t')
在生还的乘客中:
一档票价的人数:303
一档票价的人数:36
一档票价的人数:0
一档票价的人数:3
数据可视化:用柱状图展示生还者中的票价档位分布
import seaborn as sns
sns.set_context('talk')
labels = 'range 1', 'range 2', 'range 3', 'range 4'
values = [
fare_first_range_survived_count,
fare_second_range_survived_count,
fare_third_range_survived_count,
fare_fourth_range_survived_count
]
fig, ax = plt.subplots(figsize=(12, 8))
ba = ax.bar(labels, values, label='passenger', width=0.4)
ax.set_title('Fare Ranges Survived Passengers', color='w', pad=15)
ax.legend()
ax.set_xlabel('Fare Ranges', color='w')
ax.set_ylabel('Num of Passengers', color='w')
ax.set_axisbelow(True)
ax.yaxis.grid(True, color='#EEEEEE')
ax.xaxis.grid(False)
ax.bar_label(ba)
plt.xticks(color='w')
plt.yticks(color='w')
plt.show()
统计生还者和遇难者的平均票价
生还者的平均票价 = 生还者的总票价 / 生患者个数 * 100%
遇难者的统计方法类似
avg_fare_survived = round(
titanic_df.loc[titanic_df['survived'] == 1, 'fare'].sum()
/ total_survived_count,
2
)
avg_fare_dead = round(
titanic_df.loc[titanic_df['survived'] == 0, 'fare'].sum()
/ dead_passenger_num,
2
)
print('生还者的平均票价:$ '+str(avg_fare_survived))
print('遇难者的平均票价:$ '+str(avg_fare_dead))
生还者的平均票价:$ 48.4
遇难者的平均票价:$ 22.12
登船港口数据与生还的关系
len(titanic_df[titanic_df['embarked'].isnull()])
2
发现港口数据中有2个空值,因为空值较少,所以可以用 embarked 的众数填充
DataFrame 的 mode 函数用于统计每一列的数据中的众数
从结果可以看到,embarked 字段中出现最多的值是 “S”,那么就用这个值去填充这个字段的空值
titanic_df.mode()
titanic_df.loc[titanic_df['embarked'].isnull(), 'embarked'] = 'S'
从 embarked 这列的数据中去重后可以看到,所有乘客从三个港口登录
titanic_df['embarked'].drop_duplicates()
0 S
1 C
5 Q
Name: embarked, dtype: object
最后再将登陆港口的总乘客、以及从这些港口登陆的乘客的生还的情况进行一个统计。
embark_S_survived_count = len(
titanic_df.loc[
(titanic_df['embarked'] == 'S')
&
(titanic_df['survived'] == 1)
]
)
embark_S_count = len(
titanic_df.loc[
(titanic_df['embarked'] == 'S')
]
)
# ---------------------------------------
embark_C_survived_count = len(
titanic_df.loc[
(titanic_df['embarked'] == 'C')
&
(titanic_df['survived'] == 1)
]
)
embark_C_count = len(
titanic_df.loc[
(titanic_df['embarked'] == 'C')
]
)
# -------------------------------------------
embark_Q_survived_count = len(
titanic_df.loc[
(titanic_df['embarked'] == 'Q')
&
(titanic_df['survived'] == 1)
]
)
embark_Q_count = len(
titanic_df.loc[
(titanic_df['embarked'] == 'Q')
]
)
# ---------------------------------
print(
'从S港口登录的乘客共有 ' +
str(embark_S_count) + ' 人,其中 ' +
str(embark_S_survived_count) +
' 人生还,生还率为 ' +
str(round(embark_S_survived_count/embark_S_count*100, 2))
+ '%'
)
print(
'从C港口登录的乘客共有 ' +
str(embark_C_count) + ' 人,其中 ' +
str(embark_C_survived_count) +
' 人生还,生还率为 ' +
str(round(embark_C_survived_count/embark_C_count*100, 2))
+ '%'
)
print(
'从Q港口登录的乘客共有 ' +
str(embark_Q_count) + ' 人,其中 ' +
str(embark_Q_survived_count) +
' 人生还,生还率为 ' +
str(round(embark_Q_survived_count/embark_Q_count*100, 2))
+ '%'
)
从S港口登录的乘客共有 646 人,其中 219 人生还,生还率为 33.9%
从C港口登录的乘客共有 168 人,其中 93 人生还,生还率为 55.36%
从Q港口登录的乘客共有 77 人,其中 30 人生还,生还率为 38.96%
完结,谢谢大家的阅读!
相关推荐
- Python GUI 编程入门教程 第11章:数据库操作与文件管理
-
11.1数据库操作:与SQLite结合在许多应用中,数据的存储和管理是必不可少的部分。Tkinter本身并不自带数据库支持,但你可以通过Python的sqlite3模块来将数据库功能集成到Tkint...
- Python GUI 编程入门教程 第12章:图形绘制与用户交互
-
12.1图形绘制:Canvas控件Tkinter提供了一个非常强大的控件Canvas,可以用来绘制各种图形,如线条、矩形、圆形等。通过Canvas控件,用户可以在GUI中添加绘图、图像和其他复杂的内...
- Python GUI 编程入门教程 第16章:图形绘制与动画效果
-
16.1使用Canvas绘制图形Tkinter的Canvas控件是一个非常强大的绘图工具,可以用来绘制各种基本图形,如线条、矩形、圆形、文本等。Canvas允许你通过编程创建和修改图形元素,非常适合...
- Python GUI 编程入门教程 第10章:高级布局与界面美化
-
10.1高级布局管理:使用grid和placeTkinter提供了三种常用的布局管理方式:pack、grid和place。在本章中,我们重点介绍grid和place,这两种布局方式相较于pack更加...
- 手机Python编程神器——AidLearning
-
【下载和安装】1、让我们一起来看下吧,直接上图。第一眼看到是不是觉得很高逼格,暗黑画风,这很大佬。其实它就是------AidLearning。一个运行在安卓平台的linux系统,而且还包含了许多非常...
- Python GUI开发:从零开始创建桌面应用
-
在数字化时代,桌面应用依然是我们日常生活中不可或缺的一部分。无论是办公软件、游戏还是各种工具,它们都依赖于图形用户界面(GUI)来提供直观的操作体验。Python的wxPython库为我们提供了一个强...
- Python界面(GUI)编程PyQt5窗体小部件
-
一、简介在Qt(和大多数用户界面)中,“小部件”是用户可以与之交互的UI组件的名称。用户界面由布置在窗口内的多个小部件组成。Qt带有大量可用的小部件,也允许您创建自己的自定义和自定义小部件。二、小部件...
- 自学Python的8个正确顺序仅供参考
-
今天决定写一个Python新人的自学指南,好多人搞不清楚自学的顺序及路线,今天提供给大家参考一下,其实自学编程真的没有难。1【Python基础】安装并配置Python环境和编译软件Pycharm,这...
- Python | Python交互式编程神器_python交互运行
-
很多Pythoner不怎么喜欢用Python交互式界面编程,例如使用Jupyter工具。感觉交互式编程没有把代码敲完再debug舒服。但是在对一些模块/功能进行调试的时候还是非常香的。例如我在写爬虫程...
- Python GUI 编程入门教程 第14章:构建复杂图形界面
-
14.1界面布局管理在Tkinter中,界面控件的排列是通过布局管理器来实现的。Tkinter提供了三种布局管理器:pack、grid和place,每种布局管理器都有其独特的用途和优势。14.1.1...
- Python数据库编程教程:第 1 章 数据库基础与 Python 连接入门
-
1.1数据库的核心概念在开始Python数据库编程之前,我们需要先理解几个核心概念。数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它就像一个电子化的文件柜,能让我们高效...
- Python GUI 编程入门教程 第1章:Tkinter入门
-
1.1什么是Tkinter?Tkinter是Python的标准GUI库,它是Python语言的内置模块,无需额外安装。在Tkinter中,我们可以创建窗口、按钮、标签、文本框等常见的GUI元素。1....
- 用Python做个简单的登录页面_python怎么编写一个登录界面
-
我们上网时候,很多网站让你登录,没有账号注册会员,不能复制、粘贴都不让你操作。那我们怎么去实现这个窗口呢?很多语言都可以实现,根据你的需求去确定用哪个,这里我们学习python,就用tkinter测...
- Python入门学习教程:第 16 章 图形用户界面(GUI)编程
-
16.1什么是GUI编程?图形用户界面(GraphicalUserInterface,简称GUI)是指通过窗口、按钮、菜单、文本框等可视化元素与用户交互的界面。与命令行界面(CLI)相比,...
- 推荐系统实例_推荐系统有哪三个部分组成
-
协同过滤算法:#第14课:推荐系统实践-完整的协同过滤推荐系统示例#1.导入必要的库importpandasaspdfromsklearn.metrics.pairwise...
- 一周热门
- 最近发表
- 标签列表
-
- ps图案在哪里 (33)
- super().__init__ (33)
- python 获取日期 (34)
- 0xa (36)
- super().__init__()详解 (33)
- python安装包在哪里找 (33)
- linux查看python版本信息 (35)
- python怎么改成中文 (35)
- php文件怎么在浏览器运行 (33)
- eval在python中的意思 (33)
- python安装opencv库 (35)
- python div (34)
- sticky css (33)
- python中random.randint()函数 (34)
- python去掉字符串中的指定字符 (33)
- python入门经典100题 (34)
- anaconda安装路径 (34)
- yield和return的区别 (33)
- 1到10的阶乘之和是多少 (35)
- python安装sklearn库 (33)
- dom和bom区别 (33)
- js 替换指定位置的字符 (33)
- python判断元素是否存在 (33)
- sorted key (33)
- shutil.copy() (33)