pandas pd.read_csv()函數(shù)中parse_dates()參數(shù)的用法說明
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ù)時,當(dāng)我們想將多個數(shù)據(jù)寫入一個Excel表的不同DataFrame中,雖然能夠指定sheet_name參數(shù),但是會重寫整個Excel之后才會存儲。
import pandas as pd
現(xiàn)在我有三個DataFrame,分別是大眾某車型的配置、外觀和內(nèi)飾數(shù)據(jù)。現(xiàn)在我想要將這三個DF存入一張表的不同sheet中
>>> df1 220V車載電源 A/C開關(guān) ACC Autohold Aux BMBS爆胎監(jiān)測與安全控制系統(tǒng) CD機 CarPlay 0 0 0 0 0 0 0 1 >>> df2 A柱 B柱 C柱 保險杠 倒車燈 倒車鏡尺寸 前后燈 前臉 前風(fēng)窗玻璃 后視鏡尺寸 0 0 0 0 0 0 0 0 0 0 >>> df3 HUD抬頭數(shù)字顯示 中控臺 中控鎖 中控面板 中間扶手 儀表盤 兒童安全座椅接口 全景天窗 分辨率 后排出風(fēng)口 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="內(nèi)飾")
可是結(jié)果中:

只有最后一個存儲的內(nèi)飾數(shù)據(jù),并不符合我們的需求。
解決方法:
writer = pd.ExcelWriter('大眾.xlsx')
df1.to_excel(writer,"配置")
df2.to_excel(writer,"外觀")
df3.to_excel(writer,"內(nèi)飾")
writer.save()
結(jié)果:

實現(xiàn)插入相同Excel表中不同Sheet_name!
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
Python實現(xiàn)畫箱線圖展示數(shù)據(jù)分布情況
這篇文章主要介紹了Python實現(xiàn)畫箱線圖展示數(shù)據(jù)分布情況,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
python將紅底證件照轉(zhuǎn)成藍底的實現(xiàn)方法
這篇文章主要介紹了python將紅底證件照轉(zhuǎn)成藍底,本文給大家分享四種方法通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08
python之cur.fetchall與cur.fetchone提取數(shù)據(jù)并統(tǒng)計處理操作
這篇文章主要介紹了python之cur.fetchall與cur.fetchone提取數(shù)據(jù)并統(tǒng)計處理操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04

