#๐Ÿ”’ Incosistency with pandas

50 messages ยท Page 1 of 1 (latest)

edgy wedge
#

I get this error when changing file names, although nothing has changed in the files as far as I know

proper gyroBOT
#

@edgy wedge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

edgy wedge
#

Code:

haPreviousDataFile = 'Data/HA_20052024.xlsx'
haCurrentDataFile = 'Data/HA_23052024.xlsx'
i = 0


file1 = pd.read_excel(haPreviousDataFile,
                       sheet_name=0,
                        header=0,
                        index_col=False,
                        keep_default_na=True
                            )


file2 = pd.read_excel(haCurrentDataFile,
                      sheet_name=0,
                      header=0,
                      index_col=False,
                      keep_default_na=True)

endFile1 = len(file1)
endFile2 = len(file2)

file1 = file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] * 0

fileName1 = 'HA_20052024UPDATE.xlsx'
fileName2 = 'HA_23052024.xlsx'

file1.to_excel(fileName1)
file2.to_excel(fileName2)```
#

previous rendition of code

#
haPreviousDataFile = 'Data/HA_19052024.xlsx'
haCurrentDataFile = 'Data/HA_20052024.xlsx'
i = 0


file1 = pd.read_excel(haPreviousDataFile,
                       sheet_name=0,
                        header=0,
                        index_col=False,
                        keep_default_na=True
                            )


file2 = pd.read_excel(haCurrentDataFile,
                      sheet_name=0,
                      header=0,
                      index_col=False,
                      keep_default_na=True)

endFile1 = len(file1)
endFile2 = len(file2)

file1 = file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] * 0

fileName1 = 'HA_19052024UPDATE.xlsx'
fileName2 = 'HA_20052024.xlsx'

file1.to_excel(fileName1)
file2.to_excel(fileName2)```
edgy wedge
#

alright

#
  File "c:\Users\Kurasperry\Documents\Keyview Prograns\HostAway\main.py", line 26, in <module>
    file1 = file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] * 0```
fair glade
#

why are you multiplying it by 0?

edgy wedge
#

it sets the bool to false

#

which then removes all the data

#

in the series

hard yew
#

nice dp

edgy wedge
#

ong

fair glade
#

huh

#

well somehow it seems like it's implicitly converting the data to datetime

hard yew
#

if you multiply by 0 then doesnt the file1 become another datatype rather than a dataframe

fair glade
#

no

hard yew
#

ok

fair glade
#

so the goal of file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] * 0 is to effectively remove a column's data?

edgy wedge
#

forcing pandas to loop through the dataframe instead of doing it manually\

fair glade
#

you can just drop columns though why multiply by 0

edgy wedge
#

how would that look

hard yew
#

in this case you are multiplying the whole dataframe by 0 not just that one column

edgy wedge
#

if the res ID is found in file2 the entire record should be removed

hard yew
#

ohoo

#

then * 0 is not needed

#

ig

fair glade
proper gyroBOT
edgy wedge
#

so basically

#

do the check

#

throw into a new variable

#

im stupid

hard yew
#

file1 = file1[~file1['Reservation ID'].isin(file2['Reservation ID'])]

this alone returns the remaining values that are not in file2

fair glade
#

file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] this filters all the records by itself

edgy wedge
#

in a series?

#

then just drop according to the series

fair glade
#

just drop from the result of that

hard yew
#

no a dataframe

#

file1[~file1['Reservation ID'].isin(file2['Reservation ID'])]

this returns a dataframe

edgy wedge
#

and it works

#

thankies

hard yew
#

๐Ÿ™‚

edgy wedge
#

!close

proper gyroBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.