讀取檔案:
f= pd.read_csv("檔名", encoding="gb2312")
讀取檔案中某些列的資料
data = f6.loc[:, [“列名1”,“列名2”]]
假設data有這幾列{“a”,“b”,“c”}
如果a這一列的資料是{60ml,250ml,250ml,60ml,250ml,250ml,60ml,60ml,250ml,250ml,60ml,}
要只取{60,250,250,60,250,250,60,60,250,250,60,}則可以直接寫成:
data["a"]= data["a"].str.extract("(\d+)", expand=False)
data["a"].astype(int)
如果a這一列資料有小數如{8.86℃,8.86℃,8.86℃,8.86℃,8.86℃},如果有負數則正則改為:-?\d+(?:.\d+)?
data["a"]= data["a"].str.extract("(\d+(?:\.\d+)?)", expand=False)
data["a"].astype(floa
如果某一列是百分數如{55%,63%,72%,52%,72%}
data["a"].astype(float)=data["a"].astype(float)*0.01
這樣就可以得到{0.55,0.63,0.72,0.52,0.72}
讀取檔案:
f= pd.read_csv("檔名", encoding="gb2312")
讀取檔案中某些列的資料
data = f6.loc[:, [“列名1”,“列名2”]]
假設data有這幾列{“a”,“b”,“c”}
如果a這一列的資料是{60ml,250ml,250ml,60ml,250ml,250ml,60ml,60ml,250ml,250ml,60ml,}
要只取{60,250,250,60,250,250,60,60,250,250,60,}則可以直接寫成:
data["a"]= data["a"].str.extract("(\d+)", expand=False)
data["a"].astype(int)
如果a這一列資料有小數如{8.86℃,8.86℃,8.86℃,8.86℃,8.86℃},如果有負數則正則改為:-?\d+(?:.\d+)?
data["a"]= data["a"].str.extract("(\d+(?:\.\d+)?)", expand=False)
data["a"].astype(floa
如果某一列是百分數如{55%,63%,72%,52%,72%}
data["a"]= data["a"].str.extract("(\d+(?:\.\d+)?)", expand=False)
data["a"].astype(float)=data["a"].astype(float)*0.01
這樣就可以得到{0.55,0.63,0.72,0.52,0.72}