pandas 读取文件内容dataframe方法

本文介绍如何利用Python的pandas库,通过不同的方法高效地读取各种文件格式(如CSV、Excel、JSON等)内容到DataFrame中,进行数据分析前的预处理工作。
摘要由CSDN通过智能技术生成
import pandas as pd


# 获取数据
detail = pd.read_excel('meal_order_detail.xlsx', sep=',')
# print(detail)
# print(detail.index)
# print(detail.columns)
# 获取某一列数据 -- 获取菜品名称
# print(detail['dishes_name'])
# print(type(detail['dishes_name']))

# dishes_name = detail['dishes_name']
# 获取某一列数据的前五行
# 获取菜品名称前五行
# print(dishes_name[:5])
#
# # head默认获取前五行
# print(dishes_name.head())

# 获取前10行
# print(dishes_name.head(10))

# 获取后五行
# print(dishes_name[-5:])
# print(dishes_name.tail())

# 获取后10行
# print(dishes_name[-10:])

# 获取第11到20行 -->10-19
# print(dishes_name[10:20])

# 获取数据是先获取列数据,在获取行数据
# 与ndarry 进行对比: arr[行,列] --》行列同时进行选择

# 进行多列数据、多行数据筛选
# 获取多列数据, 将多个列明组成列表, 再进行放置, 再去进行筛选
# df_three_co = detail[['order_id', 'dishes_id', 'dishes_name']][:10]
# print(df_three_co)

# 通过loc与iloc进行获取数据 --同时筛选
# 使用loc方式df.loc[行名称,列名称]
# dishes_name = detail.loc[:5,'d
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值