1、 Third party libraries used :
pandas 、xlwt
2、 Get data , This time, it is entered manually
+ '\t' Purpose : Prevent input numbers from being too long , When writing a table , Written as scientific counting
# agent
jbr = input(' Please enter the name of the handler :')
# The ID number of the handler
jbrsfzh = input(' Please enter the ID number of the handler :'+'\t')
# Phone number of the handler
jbrdh = int(input(' Please enter the phone number of the handler :'))
3、 Create a workbook Set encoding
workbook=xlwt.Workbook(encoding='utf-8')
4、 Create a worksheet
sheet The name of is the page name of the table
worksheet=workbook.add_sheet('sheet1')
5、 Set the style of the table ( Including line height , Column width , Font style 、 Color, etc )
# Initialize style
style=xlwt.XFStyle()
# Create fonts for styles
font=xlwt.Font()
font.name='new'
font.height=20*16 # font size ,16 For the font size ,20 Is the unit of measurement
style.font=font
# Write column width
worksheet.col(0).width = 3333
worksheet.col(1).width = 8888
worksheet.col(2).width = 6666
6、 write in excel,
Parameters of the corresponding That's ok , Column , value
worksheet.write(1,0,jbr)
worksheet.write(1,1,jbrsfzh)
worksheet.write(1,2,jbrdh)
7、 Save to table
workbook.save('set.xls')
8、 Reading data
df=pd.read_excel('D:/gaodengtest/test_python/set.xls')
9、 Go get a line 、 The value of a column
iloc The next two values represent rows 、 Column index , You can also write only a single , Represents all data of a row or column
# first line 、 First column
jbr = df.iloc[0][0]
# The first 4 That's ok 、 The first 5 Column
jbrsfzh = int(df.iloc[3][4])
# The first 3 That's ok
jbrdh = int(df.iloc[2])