Studying recently 《 utilize python Data analysis 》, In the actual process and use of the case pandas There are still many unsolved problems in the library , Here's a summary .
As shown in the figure above , The warning shown above appears , Here's an article :https://www.jianshu.com/p/72274ccb647a
This article explains the reasons and solutions in detail , This is a chain index problem .
The general meaning of this warning is to tell you : because “c” The engine does not support regular expression delimiters ( Separator >1 Characters and different from “\s+” The delimiter of is interpreted as a regular expression ), You can specify engine=”python“ This parameter is used to avoid this warning . The details can be copied to the translation software . because Python The bottom layer of the language is C The realization of language , It can be simply understood as Python Yes, it is C Write out the . This needs to be explained by the boss , I don't quite understand the meaning . Change the code here to :
df1=pd.read_csv("movies.dat",sep='::',header=None,engine="python",names=mnames)
That's it , This is also 《 utilize python Data analysis 》 An example in the book .
take dataframe write in excel It can be used pandas Of to_excel(path,sheet1)path Is the path ,sheet1 Is the table name . But if you want to put more dataframe Write the same excel file , Need to use ExcelWriter() Method
import pandas as pd
# First create two dataframe
frame=pd.DataFrame({
"data1":random.randn(5),
"data2":random.randn(5),
"key1":["a","a","b","b","a"],
"key2":["one","two","one","two","one"]})
frame2=frame.copy()
writer=pd.ExcelWriter("test.xls")
frame.to_excel(writer,"frame")
frame2.to_excel(writer,"frame2")
writer.save()
Here are two dataframe, Write it to text file , The names of the two tables are named frame and frame2. Pay attention to the final execution writer.save() Code , Otherwise, the file will not be created , Only in cache .
If you want to put multiple dataframe Write the same table , You can use startcol and startrow These two parameters are used to implement
writer=pd.ExcelWriter("test.xls")
frame.to_excel(writer,startrow=2)
frame2.to_excel(writer,startrow=18,startcol=18)
writer.save()
#startrow Represents the starting line written ,startcol Represents the starting column written
dataframe There's something like this numpy Array similar transpose operation .
七夕來襲!是時候展現專屬於程序員的浪漫了!你打算怎麼給心愛的
Appium Its a mobile automation