python基础练习(三)—— 读取文件内容
# -*- coding: utf-8 -*-
#读入csv txt xls 等文件内容
import numpy as np
import pandas as pd
import sys
from pandas import Series, DataFrame
import xlrd, xlwt
#读入csv文件
df = pd.read_csv('D:/pytest/homeworkdata/Dress Sales.csv')
df
#读入txt文件,以 ',' 分隔
pd.read_table('D:/pytest/homeworkdata/creditcard-dataset.txt', sep=',')
#读入xls文件
path = "D:/pytest/homeworkdata/"
book = xlrd.open_workbook(path + 'ApplianceShipments.xls')
sheet_1 = book.sheet_by_name('Data')
#按行列读取数据
for c in range(sheet_1.ncols):
for r in range(sheet_1.nrows):
print sheet_1.cell(r, c).value,
print
#按行行读取数据
for c in range(sheet_1.nrows):
for r in range(sheet_1.ncols):
print sheet_1.cell(c, r).value,
print