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
MarianD
  • 13,096
  • 12
  • 42
  • 54
Moustafa
  • 11
  • 2

1 Answers1

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']

Kevin K.
  • 1,327
  • 2
  • 13
  • 18