程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

如何使用 python 操作 CSV 文件

发布于2022-10-06 22:14     阅读(207)     评论(0)     点赞(23)     收藏(1)


我用熊猫来

import pandas as pd

data = pd.read_csv('/content/sample_data/crypto_headlines.csv')

lista_de_noticias = data.to_dict('records')

我得到了这样的东西:


[{'publishdate\theadlinetext': '20130504\tCOnSTELlATIon DaG iS nOW liStEd On kucoiN eXC?haNGE'},
 {'publishdate\theadlinetext': '20130511\tItA*lys cRypTOCUrREnCy BITgrAil suspeNds OpERatIOnS'},
 {'publishdate\theadlinetext': '20130511\tTHe diffeRENCe bETWEEn sHarEs aNd cRYpToCUrReN€CiES'},
 {'publishdate\theadlinetext': '20130512\tfedS seIzE 47 mIlLION In bItCoinS in FAke ID ST=ing'},
 {'publishdate\theadlinetext': '20130514\tThE diG sTarteD ASiCboOST neTwORK AnD b@ItcoIN cAsH'},
 {'publishdate\theadlinetext': '20130516\tBINAncE far atualiZAO progRaMadA NEsTa QuarTAFEIR?a'},
 {'publishdate\theadlinetext': '20130516\ttHe EUropeaN UniOn IS pLaNninG tO rEgULAtE Bi=TcOIn'},
 {'publishdate\theadlinetext': '20130516\ti!BeROBiT HELpiNG bItcOIn To GO MAinStream IN sPaIN'},
 {'publishdate\theadlinetext': '20130521\tEuropES sMALLEr €banKS WELComE CrypTOcuRRENCy uSerS'},
 {'publishdate\theadlinetext': '20130604\tBiTcoIn btc hIghER bTc= price BRiNgs mOrE Btc SCAmS'},
 {'publishdate\theadlinetext': '20130610\tBITCOin brEAkS 9000 iN latEST LANDmARK Pr#iCE pOinT'},
 {'publishdate\theadlinetext': '20130613\tubcoiN mArkEt movEs ItS HEAdQUArTERS To €SiNgaPorE '},
 {'publishdate\theadlinetext': '20130624\treeds jEwelErs TaKinG bitCOiN ONLiNe And IN Sto$Res'},
 {'publishdate\theadlinetext': '20130705\tCoNtrOvE!RSY turnS to cLoSuRe as LItePAy SHUts DowN'},
 {'publishdate\theadlinetext': '20130709\tbUll rESiSTAncE BITCOIn pRicE nEeDs brEAK AbOve 9K*'},
 {'publishdate\theadlinetext': '20130714\tDIVoRcE DISpUte co#Uple fIghtS ovEr 830k Of BITcoin'},
 {'publishdate\theadlinetext': '20130718\t10K agaIn For BitcoiN buT oT!her CRyptOs OUTperfORM'},
 {'publishdate\theadlinetext': '20130724\tFACebOoKS liBRa crYptoCUrrency wHER$E aRE ThE BANkS'},
 {'publishdate\theadlinetext': '20130726\tCOULd eNjIn coiN ReacH A neW AlltiM=E hIGh in APRIL'},
 {'publishdate\theadlinetext': '20130827\tthe GReaT Tug of WaR betWE=eN bItCOiNS anD AltCOINs'},
 {'publishdate\theadlinetext': '20130827\tThe SacRAMento kINgs mINE EthEreuM ETh for C#HArItY'},
 {'publishdate\theadlinetext': '20130905\tcryPtOCuRREncY aTMs tHE KEY T*o WIdeSPRead ADoPtiOn'},
 {'publishdate\theadlinetext': '20130909\tGraySCales EtHereUM TRusT pRICE= VaLUeS Eth aT 6000'},
 {'publishdate\theadlinetext': '20130910\tcoINbASe GIves IRS MORe T!hAn 10k UsERS INfoRmAtIon'},
 {'publishdate\theadlinetext': '20130919\tsTRip cLuBs LaMbOS And c$ODe a tALe oF TWO bitCoins'},
 {'publishdate\theadlinetext': '20130921\tAmD WoNt PIN HOpES $on CRyPTo miNINg GrApHicS cARds'},
 {'publishdate\theadlinetext': '20131008\tBE YOUR OWn nOTAry BloCkchain pluGiN For mS$ offICe'},
 {'publishdate\theadlinetext': '20131010\tBitcoIN UP 250 frO#m bOTtoM saME aGaiN to 40000 btc'},
 {'publishdate\theadlinetext': '20131018\tcoiNbasE= leARnS VAluABlE LessOn FrOm faIlEd BUNDle'},
 {'publishdate\theadlinetext': '20131103\tBIOtRoN C$OnTRolE e MOneTizE os DaDOS que Voc CrIar'},
(...)

在此列表中,在每个字典上,我希望有 2 个键,我想将它们与 CSV publishdate\theadlinetext 分开:1)publishdate 2)theadlinetext

我还想将日期与标题文本分开。

为了做到这一点,我该如何操作 CSV?


[{'publishdate': '20130504\',
theadlinetext : tCOnSTELlATIon DaG iS nOW liStEd On kucoiN eXC?haNGE' },


解决方案


暂无回答



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/1793556/6ad505025030405e65eb/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

23 0
收藏该文
已收藏

评论内容:(最多支持255个字符)