#๐ Incosistency with pandas
50 messages ยท Page 1 of 1 (latest)
@edgy wedge
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.
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)```
send the entire traceback
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```
why are you multiplying it by 0?
nice dp
ong
if you multiply by 0 then doesnt the file1 become another datatype rather than a dataframe
no
ok
pandas is weird
so the goal of file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] * 0 is to effectively remove a column's data?
yes
forcing pandas to loop through the dataframe instead of doing it manually\
you can just drop columns though why multiply by 0
how would that look
in this case you are multiplying the whole dataframe by 0 not just that one column
that's the idea
if the res ID is found in file2 the entire record should be removed
!e
import pandas as pd
a = pd.DataFrame({'a':[1,2,3,4], 'b':[5,6,7,8]})
print(a)
a = a.drop(columns='b')
print(a)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | a b
002 | 0 1 5
003 | 1 2 6
004 | 2 3 7
005 | 3 4 8
006 | a
007 | 0 1
008 | 1 2
009 | 2 3
010 | 3 4
file1 = file1[~file1['Reservation ID'].isin(file2['Reservation ID'])]
this alone returns the remaining values that are not in file2
file1[~file1['Reservation ID'].isin(file2['Reservation ID'])] this filters all the records by itself
just drop from the result of that
no a dataframe
file1[~file1['Reservation ID'].isin(file2['Reservation ID'])]
this returns a dataframe
๐
!close
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.