How to copy data from one excel sheet to another using python

In this tutorial, we will learn how to copy data from one excel file to another in python with some cool and easy examples. In many situations, you might have to come up with this type of requirements and your confused in that situation. don’t be so confused, we have come up with the cool and tricky code.

We hope you will get help from this easy tutorial.

Copy data from one excel file to another in python

Here we are using one simple and tricky method that How to copy data from one excel sheet to another using python.

 Example: –




import csv
with open(“you excel file name”, “read cmd”) as y:
filereader=csv.reader(y)
# print(“complete reading”)
for rows in filereader:
with open(“new excel file name”, “write cmd”) as x:
filewriter=csv.writer(x)
filewriter.writerow(rows)
print(“Done copying data”)

Output:-

Done copying data

Below the program if you get a Unicode error while mentioning path directory then you should surely mention the r before the path, then you will easily avoid the Unicode error.

This below code can only replace the values in one place so that it can save only the last value if want to save full data then please give the increment in your code.

In the below code ‘r’ or ‘rb’ can be used to read the CSV file, similarly  “w” or “wb”  can be used to write in your CSV file.

Code:-

import csv
with open(r"type your path and old excel sheet name", "r") as y:
    filereader=csv.reader(y)
    for rows in filereader:p
        with open(r"type your path and new excel sheet name", "w") as x:
            filewriter=csv.writer(x)
            filewriter.writerow(rows)
print("Done copying data")
 

  

Output:-

Done copying data


3 responses to “How to copy data from one excel sheet to another using python”

  1. Manikanta Thorati says:

    Great job

  2. Sam says:

    It shows invalid syntax at line 4
    for rowsin filereader:p

Leave a Reply

Your email address will not be published. Required fields are marked *