程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Efficiency efficiency! How to read and write multiple sheet files using Python

編輯:Python

Preface

How to use Python Improve your work efficiency , Let's share this with you today .

We often use pandas Read in read write excel file , I often meet a excel There are multiple in the file sheet file , This is the time , You need to read multiple at once sheet And do corresponding data analysis or data processing , Finally, write a new excel file ( There are also many sheet). This article introduces several sheet Read in the file and write it to the new file after processing the data excel file ( Multiple sheet) Operation process .

Read the file (https://jq.qq.com/?_wv=1027&k=Ap5XvyNN)

Python Exchange of learning Q Group :660193417####
The excel In file 4 individual sheet( Sometimes how many sheet Don't know ), Now read in all sheet form .

import pandas as pd
df=pd.read_excel(' input data 123.xlsx',sheet_name=None)# Read excel all sheet data
df

all sheet The contents of are read into df in .

View all sheet name

df.keys()


View a sheet


At every sheet Add a new column

for i in df.keys():
df[i][' month ']=df[i][' Fill in the date '].astype(str).apply(lambda x:int(x[5:7]))
df



Multiple copies of data are written into one excel file ( Multiple sheet)(https://jq.qq.com/?_wv=1027&k=Ap5XvyNN)

Now write the following four copies of data into a excel The difference of documents sheet in .

writer1 = pd.ExcelWriter(' Output data 0401.xlsx',engine='xlsxwriter')
for i in df.keys():
df[i].to_excel(writer1, sheet_name=i, index=False)
worksheet1 = writer1.sheets[i]
#worksheet1.set_column(1, 1, 150)# Set the width of the column
writer1.close()

Last

This is the end of today's sharing , I hope this article can help you , If you like it, you can order a like .

I'm a panda , I'll see you in the next chapter (*◡‿◡)

Efficiency efficiency ! How to use Python Read write multiple sheet More articles about the document

  1. An overview of python Reading and writing csv xml json File operations

      Python Superior flexibility and ease of use make it one of the most popular programming languages , Especially for data scientists . This is largely due to the use of Python Dealing with large data sets is a simple thing . Now , Every technology company is developing a data strategy . ...

  2. python Read and write different codes txt file

        In the future, it will be regulated import os import codecs filenames=os.listdir(os.getcwd()) out=file("name.txt",& ...

  3. use python Read write and process csv file

    import requestsfrom bs4 import BeautifulSoupimport csv date = open('test.csv', 'w')writer = csv.writ ...

  4. python Read and write files and set character encoding of files

    One . python The code to open the file is as follows : f = open("d:\test.txt", "w") explain : The first parameter is the file name , Including paths : The second parameter is open mode mo ...

  5. [ turn ] use Python Reading and writing Excel file

    [ turn ] use Python Reading and writing Excel file   from :http://www.gocalf.com/blog/python-read-write-excel.html#xlrd-xlwt Although I communicate with data every day ...

  6. [Python] How to read and write files

    http://www.cnblogs.com/lovebread/archive/2009/12/24/1631108.html [Python] How to read and write files http://www.cnblogs.c ...

  7. python File read and write, file directory and folder operation implementation code

    This article mainly introduces python File read and write, file directory and folder operation implementation code , Friends in need can refer to For safety's sake , It's best to give the open file object a name , In this way, the file can be closed quickly after the operation is completed , Prevent some useless ...

  8. Python There are five steps to read and write files

    Python Reading and writing files are widely used in computer language , If you want to know the application , The following article will give you a detailed introduction to the relevant content , It will help you in the future learning process , Now let's introduce its application in detail . One . Open file Pytho ...

  9. 【Python Development 】python Read and write files , And set the character encoding of the file, such as utf-8

    One . python The code to open the file is as follows : f = open("d:\test.txt", "w") explain : The first parameter is the file name , Including paths : The second parameter is open mode ...

  10. Python Read and write files

    Python Read and write files 1.open Use open Remember to call the file object after opening the file close() Method . For example, you can use try/finally Statement to ensure that the file can be closed at the end . file_object = open('t ...

Random recommendation

  1. 1、 The opening : Company management experience - CEO The management experience of the company

    As a family IT The company's CEO, I am very glad to communicate with you through blog . On the one hand, I can record my growth path in the form of blog , On the other hand, I can make friends with you , Communicate with everyone about the knowledge and experience of the company's management . First , The author is in 200 ...

  2. Java Use double loop to print hourglass graphics in

    1. First, judge the outer layer ,A .B.C.D All meet the requirements 2. Then look at the inner layer A :int i=0;i<5;i++ When i=1 when ; Into the second inner loop int j=0;j<Math.abs(i)*2+1 ...

  3. 5、 ... and 、HTML Judge the input length , Experience font color changes

    <!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...

  4. Basic Virus&#39;s Infection &amp; Variation [Python]

    Learn from here Initial #!/usr/bin/python2.7 #MAGIC_STRING_skd83749872 import os import __main__ imp ...

  5. C# Document related operations

    Baidu search , The following one is quite complete .   FROM Pegasus923 http://www.cnblogs.com/pegasus923/archive/2011/01/26/1944838.html ...

  6. MySQL Series 2 :MySQL Statement operation - Technology flow ken

    brief introduction This blog will explain in detail mysql Some of the common sql Statement operation , For example, creating a database , Delete database , Create table , Modify table , Delete table , And simple query cases . About mysql In the data SQL The case of 1. Case insensitive 1. s ...

  7. How to use it snmp Protocol discovery network topology in large and complex environments

    reference :http://blog.51cto.com/13769225/2121431 For indicators, please refer to the figure below : 1. Take the interface description ( Appoint VLAN Number ) command :snmpwalk -v 2c -c Cvicse12 ...

  8. Sharing Code Between Silverlight and Win8 app metro

    This is very detailed : Sharing Code between Windows Phone 8 and Windows 8 Applications http://msdn.microsoft.com/ ...

  9. ESXI 6.5 From loading to installation

    download ESXI Visit the official website https://www.vmware.com To download, choice vsphere download esxi https://my.vmware.com/en/group/vmware/ ...

  10. use ruby Calls to perform shell command

    You need to call the operating system shell When ordered ,Ruby It provides us with six ways to complete the task : 1.Exec Method :     Kernel#exec Method replaces the current process by calling the specified command :   Example :       $ ...


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved