数据源下载链接:https://pan.baidu.com/s/1r53TtnHb5AnzjEImiR2ULw 密码:rpa7
1 读取纯文本文件
1.1 读取csv文件,使用默认的标题行、逗号分隔符
import pandas as pd
fpath = "/Users/wyn/python数据分析/ant-learn-pandas-master/datas/ml-latest-small/ratings.csv"
# 使用pd.read_csv读取数据
ratings = pd.read_csv(fpath)
# 查看前几行数据
ratings.head()
# 查看数据的形状,返回(行数,列数)
ratings.shape
# 查看列名列表
ratings.columns
# 查看索引列
ratings.index
# 查看每列的数据类型
ratings.dtypes
1.2 读取txt文件,自己指定分隔符、列名
fpath = "/Users/wyn/python数据分析/ant-learn-pandas-master/datas/crazyant/access_pvuv.txt"
pvuv = pd.read_csv(
fpath,sep=" ",
header=None,
names=['pdata','pv','uv']
)
pvuv
2 读取excel文件
fpath = "/Users/wyn/python数据分析/ant-learn-pandas-master/datas/crazyant/access_pvuv.xlsx"
pvuv = pd.read_excel(fpath)
pvuv
3 读取MySQL数据库
【暂未用到,用到再补充...】