将 学生成绩表 与 选修成绩表 进行水平的拼接
"""
Created on Wed Feb 3 14:10:41 2021@author: author: 清弦墨客(聆听)
"""
import numpy as np
import pandas as pd
# 随机生成学生成绩表
student_scores = pd.DataFrame(np.random.randint(50,100,16).reshape(4,4),index=["胡歌","林更新","金世佳","丑娟"],columns=["语文","数学","英语","Python"])
#print(student_scores)# 随机生成学生选修成绩表,并将部分成绩设为NaN
elective_scores = pd.DataFrame(np.random.randint(60,100,12).reshape(4,3),index=["胡歌","林更新","金世佳","丑娟"],columns=["体育","统计学","日语"])
elective_scores["体育"] = np.nan
elective_scores.loc["林更新":"金世佳","统计学"] = np.nan
elective_scores.loc[["胡歌","丑娟"],"日语"] = np.nan#print(elective_scores)# 学生成绩表 和 选修成绩表有共同的index,进行水平拼接
df_new = pd.concat([student_scores, elective_scores], axis=1)
print(df_new)
想在一张表中直观的了解每一位同学对应的老师
学生分配表数据下载
老师排班表数据下载
"""
Created on Wed Feb 3 14:10:41 2021@author: author: 清弦墨客(聆听)
"""
import numpy as np
import pandas as pd
# 用pandas读取xlxs文件
path = r"D:CodingPythonLogicCodingData Analyze学生分配表.xlsx"
students = pd.read_excel(path)
#print(students)path = r"D:CodingPythonLogicCodingData Analyze老师排班表.xlsx"
teachers = pd.read_excel(path)
#print(teachers)# 比较数据,发现班级是共同的列
df_new = pd.merge(students, teachers, how="inner", on="班级")
print(df_new)
需求1:通过starbucks_store_worldwide.csv数据,分析是中美的分布情况
需求2:通过starbucks_store_worldwide.csv数据,获取中国每个省份的分布数量
starbucks_store_worldwide.csv数据下载链接
"""
Created on Wed Feb 3 14:10:41 2021@author: author: 清弦墨客(聆听)
"""
import numpy as np
import pandas as pd
path = r"D:CodingPythonLogicCodingData Analyzestarbucks_store_worldwide.csv"
starbucks = pd.read_csv(path)# 先筛选出所有starbucks的店铺(因为还有别的品牌)
starbucks = starbucks[starbucks["Brand"] == "Starbucks"]# 再筛选出所有在美国的星巴克店铺(美国代码为US)
starbucks_us = starbucks[starbucks["Country"] == "US"]
print(len(starbucks_us))# 再筛选出所有在中国的星巴克店铺(中国代码为CN)
starbucks_cn = starbucks[starbucks["Country"] == "CN"]
print(len(starbucks_cn))# 结果显示美国13311家,中国2734家,还是美国的多。# 将筛选过的中国数据保存一下,方便观察,不保存也行
path = r"D:CodingPythonLogicCodingData Analyzestarbucks_china.xlsx"
_excel(path,encoding="utf-8")# 使用groupby聚合,统计每个城市星巴克店的数量
starbucks_cn_group = upby(by="City")["City"].count()
print(starbucks_cn_group)# 保存结果
path = r"D:CodingPythonLogicCodingData Analyzestarbucks_china_group.xlsx"
starbucks__excel(path,encoding="utf-8")# 从统计结果来看,开店最多的地方是上海和香港
本文发布于:2024-02-04 20:00:55,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170715380159142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |