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列的值作為獨(dú)立的日期列;
list of lists. e.g. If [[1, 3]] -> 合并1,3列作為一個(gè)日期列使用
dict, e.g. {‘foo' : [1, 3]} -> 將1,3列合并,并給合并后的列起名為"foo"
補(bǔ)充:解決Pandas的to_excel()寫入不同Sheet,而不會(huì)被重寫
在使用Pandas的to_excel()方法寫入數(shù)據(jù)時(shí),當(dāng)我們想將多個(gè)數(shù)據(jù)寫入一個(gè)Excel表的不同DataFrame中,雖然能夠指定sheet_name參數(shù),但是會(huì)重寫整個(gè)Excel之后才會(huì)存儲(chǔ)。
import pandas as pd
現(xiàn)在我有三個(gè)DataFrame,分別是大眾某車型的配置、外觀和內(nèi)飾數(shù)據(jù)?,F(xiàn)在我想要將這三個(gè)DF存入一張表的不同sheet中
>>> df1 220V車載電源 A/C開關(guān) ACC Autohold Aux BMBS爆胎監(jiān)測與安全控制系統(tǒng) CD機(jī) CarPlay 0 0 0 0 0 0 0 1 >>> df2 A柱 B柱 C柱 保險(xiǎn)杠 倒車燈 倒車鏡尺寸 前后燈 前臉 前風(fēng)窗玻璃 后視鏡尺寸 0 0 0 0 0 0 0 0 0 0 >>> df3 HUD抬頭數(shù)字顯示 中控臺(tái) 中控鎖 中控面板 中間扶手 儀表盤 兒童安全座椅接口 全景天窗 分辨率 后排出風(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é)果中:
只有最后一個(gè)存儲(chǔ)的內(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é)果:
實(shí)現(xiàn)插入相同Excel表中不同Sheet_name!
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
Python?eval()和exec()函數(shù)使用詳解
exec函數(shù)執(zhí)行的是python語句,沒有返回值,eval函數(shù)執(zhí)行的是python表達(dá)式,有返回值,exec函數(shù)和eval函數(shù)都可以傳入命名空間作為參數(shù),本文給大家介紹下Python?eval()和exec()函數(shù),感興趣的朋友跟隨小編一起看看吧2022-11-11用Python爬取各大高校并可視化幫弟弟選大學(xué),弟弟直呼牛X
高考結(jié)束了,接下來最重要的就是玩玩玩,然后準(zhǔn)備報(bào)志愿吧.中國教育在線網(wǎng)顯示國內(nèi)目前共有2857所高等院校,報(bào)一個(gè)理想的學(xué)校簡直是千里挑一.正好表弟求著我讓我?guī)退x學(xué)校,我想著十年寒窗苦讀也不容易不如就用python幫幫他.分析一下目前國內(nèi)的大學(xué),需要的朋友可以參考下2021-06-06Django 在iframe里跳轉(zhuǎn)頂層url的例子
今天小編就為大家分享一篇Django 在iframe里跳轉(zhuǎn)頂層url的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-08-08