1

I'm new to Python and I'm trying to make a program that automate some daily Excel work.

I just want to copy data from a sheet to another using pandas but I got an error. Can anyone help?

import pandas as pd

File1 = pd.read_excel('FileName1.xlsx', sheet_name='Sheet1')
print(File1.columns)
print(File1['Date'][2])
File2 = pd.read_excel('FileName2.xlsx', sheet_name='Sheet2')
File1['Date'][0] = File2['Date'][0]

Here's the error:

SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame
2
  • 1
    probably this will be helpful: stackoverflow.com/questions/20625582/… Commented Aug 15, 2018 at 13:26
  • I saw it before but I didn't understand at first, anyway thank you. Commented Aug 15, 2018 at 13:36

1 Answer 1

1

Your error is being thrown in the statement File1['Date'][0] = File2['Date'][0]. Pandas does not allow assignment using indexes like typical lists. Try using indexing with loc: File1.loc[0, 'Date'] = File2.loc[0, 'Date']

Sign up to request clarification or add additional context in comments.

3 Comments

Would you please tell me how to save these changes?
You can use pd.to_excel('FileName1.xlsx')
I've got an error : module pandas has no attribute 'to_excel'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.