- Hands-On Data Science with Anaconda
- Dr. Yuxing Yan James Yan
- 152字
- 2021-06-25 21:08:50
Data output
In the previous section, by using the R language, we generated a data asset called final. To save it to a CSV file, we could use the write.csv() or write.table() functions, shown in the code here:
> write.csv(final,file="c:/temp/t.csv") > write.table(final,file="c:/temp/t2.txt",sep=";")
The separator for the write.csv() function is a comma, while we can specify our own separator for the write.table() function. To find out the other R functions starting with write, we could use the apropos() function, shown here:
> apropos("^write") [1] "write" "write.csv" "write.csv2" [4] "write.dcf" "write.ftable" "write.socket" [7] "write.table" "writeBin" "writeChar" [10] "writeClipboard" "writeLines"
For the following Python program, we export Fama-French monthly factors to three different output formats, pickle, CSV, and text files:
import pandas as pd infile="http://canisius.edu/~yany/data/ff3monthly.csv" ff3=pd.read_csv(infile,skiprows=3) print(ff3.head(2)) # output to pickle ff3.to_pickle("c:/temp/ff3.pkl") # output to a csv file outfile=open("c:/temp/ff3.csv","w") ff3.to_csv(outfile,index=None) outfile.close() # output to text file outfile2=open("c:/temp/ff3.txt","w") ff3.to_csv(outfile2, header=True, index=None, sep=' ', mode='a') outfile2.close()
推薦閱讀
- Cinema 4D R13 Cookbook
- 傳感器技術(shù)實驗教程
- Photoshop CS4經(jīng)典380例
- Effective DevOps with AWS
- CompTIA Network+ Certification Guide
- AutoCAD 2012中文版繪圖設(shè)計高手速成
- 大數(shù)據(jù)驅(qū)動的設(shè)備健康預(yù)測及維護決策優(yōu)化
- PostgreSQL 10 Administration Cookbook
- 運動控制系統(tǒng)
- Photoshop行業(yè)應(yīng)用基礎(chǔ)
- 過程控制系統(tǒng)
- 經(jīng)典Java EE企業(yè)應(yīng)用實戰(zhàn)
- 手把手教你學Flash CS3
- 菜鳥起飛電腦組裝·維護與故障排查
- x86/x64體系探索及編程