一、前言
在python爬蟲抓取拉勾網職業信息這篇博客中,已經抓取了拉勾網數據分析職位的信息并儲存在本地,下面介紹一下如果將txt文檔轉化為csv文檔。
二、實戰
這里要注意的是,為了在sas中數據步編寫方便,爬蟲儲存在本地的數據格式有所改動,后邊會詳細說明。
1、數據讀取
libname lagou 'F:/lagou';filename intxt 'F:/lagou/深圳.txt';filename outcsv 'F:/lagou/深圳.csv';data lagou.sz; infile intxt firstobs=2; length companyName $60. companyType $20. companyStage $20. companyLabel $60. companySize $10. companyDistrict $10. positionType $15. positionEducation $10. positionAdvantage $60. positionSalary $10. positionWorkYear $10.; input companyName companyType companyStage companyLabel companySize companyDistrict positionType positionEducation positionAdvantage positionSalary positionWorkYear;run;在上面可以看到,讀取文件的時候,分隔符使用的是默認的空格,這與之前爬蟲抓取時存儲的數據格式有所不同,需要自行修改。因為數據第一行是標簽名,所以從第二個觀測開始讀取,length語句保證數據長度足夠,結果如下:
2、轉化為csv文檔
option nocenter;ods listing close;ods results off;ods csvall file=outcsv; PRoc print data=lagou.sz; title '2017年拉勾網深圳數據分析職位信息'; run;ods csvall close;ods results on;ods listing;option nocenter將將輸出的文件內容局左,ods listing close關閉到output窗口的默認輸出,ods result off關閉默認到result的輸出,結果如下:
3、到這里將txt文檔轉為csv文檔就結束了
新聞熱點
疑難解答