当前位置: 首页 > 后端技术 > Python

python数据分析-pandasexcel基本数据操作(补充篇)

时间:2023-03-26 16:33:12 Python

1.下载并导入相关扩展库1#下载扩展库2pipinstallxlrd3pipinstallpandas4#-*-coding:UTF-8-*-56#导入pandas库7importpandasaspd2,准备数据文件3,读取文件worksheet1#读取excel文件指定worksheet数据23print("Worksheet:data1数据内容")4data_fram_data1=pd.read_excel('C:/python集中营/pandas操作excel数据/data.xls',sheet_name='data1')5print(data_fram_data1)67print("Worksheet:data2数据内容")8data_fram_data2=pd.read_excel('C:/python集中营/pandas操作excel数据/data.xls',sheet_name='data2')9print(data_fram_data2)1011print("worksheet:data3数据内容")12data_fram_data3=pd.read_excel('C:/python集中营/pandas操作exceldata/data.xls',sheet_name='data3')13print(data_fram_data3)4、excel1的基本操作#查看全部列名2print(data_fram_data3.columns)3#查看数据类型4print(data_fram_data3.dtypes)56#查看前10行sofdata7print(data_fram_data3.head(10))8#查看name到age的所有列数据9print(data_fram_data3.loc[:,'Name':'Age'])10#查看第一到第三行,所有列从姓名到年龄的数据11print(data_fram_data3.loc[1:3,'Name':'Age'])1213#删除姓名列14data_fram_data3=data_fram_data3.drop(['name'],axis=1)15print(data_fram_data3)16#删除age==6行17data_fram_data3=data_fram_data3.loc[-(data_fram_data3['age']==6)]18print(data_fram_data3)1920#去除年龄重复数据21data_fram_data3=data_fram_data3.drop_duplicates(['age'])22print(data_fram_data3)更多精彩去微信公众号【Python集中营】,专注python技术栈、数据获取、社区交流、干货分享,期待你的加入~