pandas中pd.read_csv()函數的parse_dates()參數如何解決?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
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()方法寫入數據時,當我們想將多個數據寫入一個Excel表的不同DataFrame中,雖然能夠指定sheet_name參數,但是會重寫整個Excel之后才會存儲。
import pandas as pd
現在我有三個DataFrame,分別是大眾某車型的配置、外觀和內飾數據?,F在我想要將這三個DF存入一張表的不同sheet中
>>> df1 220V車載電源 A/C開關 ACC Autohold Aux BMBS爆胎監測與安全控制系統 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抬頭數字顯示 中控臺 中控鎖 中控面板 中間扶手 儀表盤 兒童安全座椅接口 全景天窗 分辨率 后排出風口 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="內飾")
可是結果中:
只有最后一個存儲的內飾數據,并不符合我們的需求。
writer = pd.ExcelWriter('大眾.xlsx') df1.to_excel(writer,"配置") df2.to_excel(writer,"外觀") df3.to_excel(writer,"內飾") writer.save()
結果:
看完上述內容,你們掌握pandas中pd.read_csv()函數的parse_dates()參數如何解決的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。