parse_dates : boolean or list of ints or names or list of lists or dict, default False
boolean. If True -> try parsing the index.
list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column.
list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column.
dict, e.g. {‘foo' : [1, 3]} -> parse columns 1, 3 as date and call result ‘foo'
If a column or index contains an unparseable date, the entire column or index will be returned unaltered as an object data
type. For non-standard datetime parsing, use pd.to_datetime after pd.read_csv
中文解釋:
boolean. True -> 解析索引
list of ints or names. e.g. If [1, 2, 3] -> 解析1,2,3列的值作為獨立的日期列;
list of lists. e.g. If [[1, 3]] -> 合并1,3列作為一個日期列使用
dict, e.g. {‘foo' : [1, 3]} -> 將1,3列合并,并給合并后的列起名為"foo"
補充:解決Pandas的to_excel()寫入不同Sheet,而不會被重寫
在使用Pandas的to_excel()方法寫入數(shù)據(jù)時,當我們想將多個數(shù)據(jù)寫入一個Excel表的不同DataFrame中,雖然能夠指定sheet_name參數(shù),但是會重寫整個Excel之后才會存儲。
import pandas as pd
現(xiàn)在我有三個DataFrame,分別是大眾某車型的配置、外觀和內飾數(shù)據(jù)?,F(xiàn)在我想要將這三個DF存入一張表的不同sheet中
>>> df1 220V車載電源 A/C開關 ACC Autohold Aux BMBS爆胎監(jiān)測與安全控制系統(tǒng) CD機 CarPlay 0 0 0 0 0 0 0 1 >>> df2 A柱 B柱 C柱 保險杠 倒車燈 倒車鏡尺寸 前后燈 前臉 前風窗玻璃 后視鏡尺寸 0 0 0 0 0 0 0 0 0 0 >>> df3 HUD抬頭數(shù)字顯示 中控臺 中控鎖 中控面板 中間扶手 儀表盤 兒童安全座椅接口 全景天窗 分辨率 后排出風口 0 0 4 5 0 0 13 0 0 0
df1.to_excel("大眾.xlsx",sheet_name="配置") df2.to_excel("大眾.xlsx",sheet_name="外觀") df3.to_excel("大眾.xlsx",sheet_name="內飾")
可是結果中:
只有最后一個存儲的內飾數(shù)據(jù),并不符合我們的需求。
writer = pd.ExcelWriter('大眾.xlsx') df1.to_excel(writer,"配置") df2.to_excel(writer,"外觀") df3.to_excel(writer,"內飾") writer.save()
結果:
實現(xiàn)插入相同Excel表中不同Sheet_name!
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
標簽:昭通 信陽 阜新 合肥 淘寶好評回訪 隨州 興安盟 濟源
巨人網絡通訊聲明:本文標題《pandas pd.read_csv()函數(shù)中parse_dates()參數(shù)的用法說明》,本文關鍵詞 pandas,pd.read,csv,函數(shù),中,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。