分类:pandas
2021
01-22
2021
01-17
一、获取DataFrame列标签importpandasaspdfile_path='/Users/Arithmetic/da-rnn-master/data/collectd67_power_after_test_smooth.csv'dataset=pd.read_csv(file_path)cols=list(dataset)['ps_state-stopped','ps_state-running','ps_state-blocked','ps_state-paging','ps_state-sleeping','ps_state-zombies','fork_rate','cpu-2-system','cpu-2-nice','cpu-2-steal',...]二、改变列标签为指定顺序importpa...
继续阅读 >
数据importnumpyasnpimportpandasaspddata=[{'Name':'小明','Chinese':[70,80],'Math':[90,80]},{'Name':'小红','Chinese':[70,80,90],'Math':[90,80,70]}]data=pd.DataFrame(data)data拆分成行defsplit_row(data,column):'''拆分成行:paramdata:原始数据:paramcolumn:拆分的列名:typedata:pandas.core.frame.DataFrame:typecolumn:str'''row_len=list(map(len,data[col...
继续阅读 >
按照某一列排序d={'A':[3,6,6,7,9],'B':[2,5,8,0,0]}df=pd.DataFrame(data=d)print('排序前:\n',df)'''排序前:AB032165268370490'''res=df.sort_values(by='A',ascending=False)print('按照A列的值排序:\n',res)'''按照A列的值排序:AB490370165268032'''按照多列排序d={'A':[3,6,6,7,9],'B':[2,5,8,0,0]}df=pd.DataFrame(data=d)print('排序前:\n',df)'''排序前:AB...
继续阅读 >
创建测试数据:importpandasaspdimportnumpyasnp#CreateaDataFramedf1={'Subject':['semester1','semester2','semester3','semester4','semester1','semester2','semester3'],'Score':[62,47,55,74,31,77,85]}df2={'Subject':['semester1','semester2','semester3','semester4'],'Score':[90,47,85,74]}df1=pd.DataFrame(df1,columns=['Subject','Score'])df2=pd.DataFrame(df2,columns=['Sub...
继续阅读 >
本文主要介绍了pandas导出数据到文件的四种方式,分享给大家,主要也是给自己留个笔记,具体如下:importpandasaspdimportpymysqldf=pd.DataFrame({'A':[3,4,8,9],'B':[1.2,2.4,4.5,7.3],'C':["aa","bb","cc","dd"]})defexport_data_to_csv():#参数encoding="utf_8_sig"编码后,可以防止写入csv的中文出现乱码df.to_csv("./test.csv",encoding="utf_8_sig")defexport_data_to_excel():#encodi...
继续阅读 >