pandas-19 DataFrame读取写入文件的方法
2024-08-30 14:22:45
pandas-19 DataFrame读取写入文件的方法
DataFrame有非常丰富的IO方法,比如DataFrame读写csv文件excel文件等等,操作很简单。下面在代码中标记出来一些常用的读写操作方法,需要的时候查询一下该方法就可以了。
df1.to_csv(‘df1.csv’) # 默认会把 index 也当成一列写入到文件中
df1.to_csv(‘df2.csv’, index=False) # 如果不想显示索引,可以添加第二个参数 index = False
df1.to_json(‘df1.csv’) 写入到json文件
df1.to_excel(‘df1.xlsx’) 写入到excel文件
更多例子参考如下:
import pandas as pd
from pandas import Series, DataFrame
import webbrowser
link = 'http://pandas.pydata.org/pandas-docs/version/0.20/io.html'
webbrowser.open(link)
df1 = pd.read_clipboard()
print(df1)
'''
Format Type Data Description Reader Writer
0 text CSV read_csv to_csv
1 text JSON read_json to_json
2 text HTML read_html to_html
3 text Local clipboard read_clipboard to_clipboard
4 binary MS Excel read_excel to_excel
5 binary HDF5 Format read_hdf to_hdf
6 binary Feather Format read_feather to_feather
7 binary Msgpack read_msgpack to_msgpack
8 binary Stata read_stata to_stata
9 binary SAS read_sas
10 binary Python Pickle Format read_pickle to_pickle
11 SQL SQL read_sql to_sql
12 SQL Google Big Query read_gbq to_gbq
'''
df1.to_csv('df1.csv') # 默认会把 index 也当成一列写入到文件中
df1.to_csv('df2.csv', index=False) # 如果不想显示索引,可以添加第二个参数 index = False
print(df1.to_json())
df1.to_excel('df1.xlsx')
最新文章
- javascript的快速排序法
- python脚本实现scp上传下载功能
- 基于MST的立体匹配及相关改进(A Non-Local Cost Aggregation Method for Stereo Matching)
- Sublime 3 如何设置xftp 保存自动上传
- linux ssh publickey登录
- 基于 VLC 的 Android 多媒体解决方案
- 常见的MIME类型
- 2001: [Hnoi2010]City 城市建设 - BZOJ
- 《转》前端性能优化----yahoo前端性能团队总结的35条黄金定律
- HibernateTool的安装和使用(Eclipse中)
- MVC3+EF4.1学习系列(九)-----EF4.1其他的一些技巧的使用
- sql执行机制
- JavaWeb框架_Struts2_(六)----->;Struts2的输入校验
- 【托业】【怪兽】TEST04
- webpos登录不上
- File重要获取功能
- UVA524 素数环 Prime Ring Problem
- 详解javascript中this的工作原理
- 版本适配 sdk version MD
- Spring Boot 集成 Redis 实现缓存机制
热门文章
- 安装elasticsearch+kibana+searchguard
- @TableField
- org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next tok
- python基础语法19 面向对象总结,pickle保存对象注意事项
- 从websocket协议出发,了解应用层协议,传输层协议,网络的7层协议
- 【java】oracle好用,但java运行缺失右括号
- csv与openpyxl函数
- qbxt济南七日(游)学习
- 洛谷 p1047 校门外的树 线段树做法
- [Usaco2012 Feb] Cow Coupons