# -*- coding: utf-8 -*-
"""
Created on Wed Mar 27 19:44:59 2019
@author: Emma
"""
#简单导入代码
import pandas as pd
import numpy as np
Filename = r'F:\信科工作文件\课件\数据科学入门课件\alco2009.xlsx'
alco2009 = pd.DataFrame(pd.read_excel(Filename))
#第二种方法,主要练习学习的知识点
import xlrd
def read_excel():
workbook = xlrd.open_workbook(r'F:\信科工作文件\课件\数据科学入门课件\alco2009.xlsx')
sheet1 = workbook.sheet_by_name('Sheet1')
print(sheet1.nrows,sheet1.ncols)
cols0 = sheet1.col_values(0)
del(cols0[0]) #删除第一列的空格元素
cols1 = sheet1.col_values(1)
cols2 = sheet1.col_values(2)
cols3 = sheet1.col_values(3)
#生成一个元组列表
data = [(cols1[i],cols2[i],cols3[i]) for i in range(1,sheet1.nrows)]
return data, cols0
if __name__ == '__main__':
read_excel()
alco2009_list, index_state = read_excel()
alco2009_2 = pd.DataFrame(alco2009_list,
columns=('Beer','Wine','Spirits'),
index=tuple(index_state))
python---读取alco2009
最新推荐文章于 2024-06-16 08:13:28 发布