09-DataFrame的 io
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import webbrowser
link = "http://pandas.pydata.org/pandas-docs/stable/reference/io.html"
webbrowser.open( link )
1. 从粘贴板读取或写到粘贴板
手工右键复制一下,
web, name 0 http://www.baidu.com, sitexxx, 1 http://www.sougou.com, sitexxx, 2 http://wwss.coms, sitexxx, 3 http://ww.scs.co, sitexxx,
然后执行 读取右键剪贴板中的数据
df = pd.read_clipboard()
把df 放到右键去。(特别适合,粘贴到excel中)
df.to_clipboard()
excell 可以按照粘贴板,进行格式化粘贴。
DataFrame <-> CSV
2. 将 DataFrame 存放到 csv 文件中 (写入操作)
copy.to_csv('df1.csv') // 会默认带了首列的 序号 0,1,2,3,4,....
设置 index=False
copy.to_csv('df1.csv', index= False)
3. CSV 读取操作
df2 = pd.read_csv('df1.csv)
pd.read_csv('df.csv')
DataFrame <-> Json
df1.to_json()
df1.read_json( df1.to_json() )
DataFrame <-> Html
df1.to_html()
df.to_html("df.html")
DataFrame <-> excell
df1.to_excel( 'df.xlsx' )
DataFrame <-> SQL的支持 非常重要
pandas 的官方文档手册
》 http://pandas.pydata.org/pandas-docs/stable/reference/io.html#stata


浙公网安备 33010602011771号