没有合适的资源?快使用搜索试试~ 我知道了~
首页数据清洗之 csv文件读写
数据清洗之 csv文件读写
17 下载量 201 浏览量
更新于2023-03-03
评论 2
收藏 130KB PDF 举报
csv文件读写 pandas内置了10多种数据源读取函数,常见的就是CSV和EXCEL 使用read_csv方式读取。结果为dataframe格式 在读取csv文件时,文件名称尽量是英文 参数较多,可以自行控制,但很多时候用默认参数 读取csv时,注意编码,常用编码为utf-8、gbk、gbk2312和gb18030等 使用to_csv方法快速保存 import numpy as np import pandas as pd import os os.getcwd() 'D:\\Jupyter\\notebook\\Python数据清洗实战\\数据清洗之文件读写' os.chdir('D
资源详情
资源评论
资源推荐
数据清洗之数据清洗之 csv文件读写文件读写
csv文件读写文件读写
pandas内置了10多种数据源读取函数,常见的就是CSV和EXCEL
使用read_csv方式读取。结果为dataframe格式
在读取csv文件时,文件名称尽量是英文
参数较多,可以自行控制,但很多时候用默认参数
读取csv时,注意编码,常用编码为utf-8、gbk、gbk2312和gb18030等
使用to_csv方法快速保存
import numpy as np
import pandas as pd
import os
os.getcwd()
'D:\Jupyter\notebook\Python数据清洗实战\数据清洗之文件读写'
os.chdir('D:\Jupyter\notebook\Python数据清洗实战\数据')
baby = pd.read_csv('sam_tianchi_mum_baby.csv', encoding='utf-8')
baby.head(5)
user_id birthday gender
0 2757 20130311 1
1 415971 20121111 0
2 1372572 20120130 1
3 10339332 20110910 0
4 10642245 20130213 0
order = pd.read_csv('meal_order_info.csv', encoding='gbk', dtype={'info_id':str, 'emp_id':str})
order.info()
RangeIndex: 945 entries, 0 to 944
Data columns (total 21 columns):
info_id 945 non-null object
emp_id 945 non-null object
number_consumers 945 non-null int64
mode 0 non-null float64
dining_table_id 945 non-null int64
dining_table_name 945 non-null int64
expenditure 945 non-null int64
dishes_count 945 non-null int64
accounts_payable 945 non-null int64
use_start_time 945 non-null object
check_closed 0 non-null float64
lock_time 936 non-null object
cashier_id 0 non-null float64
pc_id 0 non-null float64
order_number 0 non-null float64
org_id 945 non-null int64
print_doc_bill_num 0 non-null float64
lock_table_info 0 non-null float64
order_status 945 non-null int64
phone 945 non-null int64
name 945 non-null object
dtypes: float64(7), int64(9), object(5)
memory usage: 155.1+ KB
order.head(5)
info_id emp_id number_consumers mode dining_table_id dining_table_name expenditure dishes_count accounts_payable use_start_time … lock_time cashier_id pc_id order_number
0 417 1442 4 NaN 1501 1022 165 5 165
2016/8/1
11:05:36
…
2016/8/1
11:11:46
NaN NaN NaN
1 301 1095 3 NaN 1430 1031 321 6 321
2016/8/1
11:15:57
…
2016/8/1
11:31:55
NaN NaN NaN
2 413 1147 6 NaN 1488 1009 854 15 854
2016/8/1
12:42:52
…
2016/8/1
12:54:37
NaN NaN NaN
3 415 1166 4 NaN 1502 1023 466 10 466
2016/8/1
12:51:38
…
2016/8/1
13:08:20
NaN NaN NaN
4 392 1094 10 NaN 1499 1020 704 24 704
2016/8/1
12:58:44
…
2016/8/1
13:07:16
NaN NaN NaN
5 rows × 21 columns
baby = pd.read_csv('baby_trade_history.csv', nrows=100) # 读取前100行
baby
user_id auction_id cat_id cat1 property buy_mount day
0 786295544 41098319944 50014866 50022520 21458:86755362;13023209:3593274;10984217:21985… 2 20140919
1 532110457 17916191097 50011993 28 21458:11399317;1628862:3251296;21475:137325;16… 1 20131011
2 249013725 21896936223 50012461 50014815 21458:30992;1628665:92012;1628665:3233938;1628… 1 20131011
3 917056007 12515996043 50018831 50014815 21458:15841995;21956:3494076;27000458:59723383… 2 20141023
4 444069173 20487688075 50013636 50008168 21458:30992;13658074:3323064;1628665:3233941;1… 1 20141103
5 152298847 41840167463 121394024 50008168 21458:3408353;13023209:727117752;22009:2741771… 1 20141103
6 513441334 19909384116 50010557 50008168 25935:21991;1628665:29784;22019:34731;22019:20… 1 20121212
7 297411659 13540124907 50010542 50008168 21458:60020529;25935:31381;1633959:27247291;16… 1 20121212
8 82830661 19948600790 50013874 28 21458:11580;21475:137325 1 20121101
9 475046636 10368360710 203527 28 22724:40168;22729:40278;21458:21817;2770200:24… 1 20121101
10 734147966 15307958346 50018202 38 21458:3270827;7361532:28710594;7397093:7536994… 2 20121101
11 68547330 21162876126 50012365 122650008 1628665:3233941;1628665:3233942;1628665:323393… 1 20121123
12 697081418 15898050723 50013636 50008168 21458:19726868;1633959:179425852;13836282:1290… 1 20121123
13 377550424 15771663914 50015841 28 1628665:3233941;1628665:3233942;3914866:11580;… 1 20121123
14 88313935 22532727492 50013711 50008168 1628665:3233941;1628665:3233942;22019:3340598;… 1 20131005
15 25918750 16078389250 50012359 122650008 21458:3405407;1633959:6186201;1628366:32799;81… 1 20131005
16 350288528 35086271572 50010544 50008168 21458:61813;25935:21991;1628665:3233938;162866… 1 20131129
17 348090113 17436967558 50009540 50014815 21458:21910;3110425:30696849;2191928:75373546;… 1 20131129
18 1635282280 36153356431 50013207 50008168 1628665:29784;1628665:29799;2904342:31004;2201… 1 20131129
19 530850018 22058239899 50024147 28 21458:205007542;43307470:5543413;2339128:62147… 1 20140210
weixin_38620314
- 粉丝: 1
- 资源: 914
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0