99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀基于python批量處理dat文件及科學計算方法詳解
基于python批量處理dat文件及科學計算方法詳解
2018-06-17
收藏

基于python批量處理dat文件及科學計算方法詳解

今天小編就為大家分享一篇基于python批量處理dat文件及科學計算方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
批處理文件功能    
import os
path1 = 'C:\\Users\\awake_ljw\\Documents\\python for data analysis\\test1'
path2 = 'C:\\Users\\awake_ljw\\Documents\\python for data analysis\\test2'
filelist = os.listdir(path1)
for files in filelist:
 Olddir = os.path.join(path1,files)
 filename = os.path.splitext(files)[0]
 filetype = os.path.splitext(files)[1]
 print Olddir
 file_test = open(Olddir,'r')
 Newdir = os.path.join(path2,str(filename)+'.csv')
 print Newdir
 file_test2 = open(Newdir,'w')
 for lines in file_test.readlines():
 strdata = ",".join(lines.split('\t'))
 file_test2.write(strdata)
 file_test.close()
 file_test2.close()
os模塊是python最基礎的模塊之一,一般用于文件處理等操作。上面這段代碼主要就是將dat文件轉化為csv文件,同時保證csv可讀。一般txt文件不能通過直接改后綴改變呈csv文件格式,一般會造成文件不可讀。csv文件一般通過逗號分隔文本,數(shù)據處理起來較得心應手,可以直接改后綴得到xlsx文件,一般excel也可讀。
科學計算
matlab作為一門科學計算編程語言,在科學計算的應用實在廣泛,包括webread等強大的函數(shù)用起來十分順手,但matlab是商業(yè)軟件,并不免費。其實,python在科學計算效率或函數(shù)庫功能包括其繪圖功能、圖像處理都很強大,(相比matlab,python的調色板更出色)。以下列舉一些數(shù)據文件讀取,繪圖的一些基本操作作為參考。
數(shù)據提取及繪圖    
#數(shù)據提取
import os
import pandas as pd
import numpy as np
number = -1;
sudu=np.zeros(5247*5,dtype=float).reshape(5247,5)
for files in filelist1:
 number +=1
 data = pd.read_csv(str(number+1)+'a.csv')
 sudu[:,number]=data['velocity']
 x = data['x']
 y = data['y']
a = sudu[0:5184,0].reshape(81,64)
%matplotlib inline
import matplotlib.pyplot as plt
extent = [np.min(x),np.max(x),np.min(y),np.max(y)]
plt.subplot(231)
u0 = sudu[0:5184,0].reshape(81,64)
plt.imshow(u0,extent=extent,origin='lower')
plt.subplot(232)
u1 = sudu[0:5184,1].reshape(81,64)
plt.imshow(u1,extent=extent,origin='lower')
plt.subplot(233)
u2 = sudu[0:5184,2].reshape(81,64)
plt.imshow(u2,extent=extent,origin='lower')
plt.subplot(234)
u3 = sudu[0:5184,3].reshape(81,64)
plt.imshow(u3,extent=extent,origin='lower')
#plt.axis("equal")
plt.subplot(235)
u4 = sudu[0:5184,4].reshape(81,64)
plt.imshow(u4,extent=extent,origin='lower')
plt.subplot(236)
u5 = sudu[0:5184,4].reshape(81,64)
plt.imshow(u5,extent=extent,origin='lower')
#contour
cs = plt.contour(u5, 20,extent = extent)
plt.xlim(-0.8,0.8)
plt.ylim(0.6,2.2)

plt.axis('equal')


python的科學計算功能與matlab及其相似,python有幾點不同在于

1.python有元組的數(shù)據類型,元組不同于列表,元組不可更改

2.python的數(shù)據檢索使用[]

總而言之,python的數(shù)據形式及其豐富。

numpy以及pandaspython用于數(shù)據處理的兩個庫,具體使用方法主要推薦python科學計算這本書。matplotlib用于繪圖,剛也說了,其調色板很厲害哦,圖像質量不錯。

預告:代碼運行環(huán)境均為jupyter notebook,簡直神器一般的存在,網上搭建的資料也太多。



數(shù)據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調,回調的第一個參數(shù)驗證碼對象,之后可以使用它調用相應的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }