#๐ Matching data from two files and outputting into a new file issue
91 messages ยท Page 1 of 1 (latest)
@civic gate
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.
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
thank u i will reupload using this
@civic gate we use this for code
Im trying to write a function that would take data from a new input file, and parse this data using the previous two output files, taking data from the second functions output and writing it into the previous output file from the first function
two things i've spotted:
- you don't need an absolute file - python works fine with relative ones (just
"input.txt"works) - you don't need an
encodingvariable
so i can remove the filepath? that would help alot tbh
i had the encoding because i was getting errors surrounding it
can you rephrase this? call both files A and B - specify their format, content and the operations you want to perform on then
yes
ok thank u
just manually write encoding = "utf8"
also what is this for?
what are you trying to achieve with this?
answer this first though
So i have the first function taking raw data from input.txt (file A1) and filtering and arranging it then written into output.txt (file B1)
The second function takes raw data from groupinput.txt (file A2) and again filters and arranges it so it only shows the relevant data into groupoutput.txt (file B2)
I need a third function that now takes data from a new file, file A3 and uses file B2 and file B1 to write it into file B3 by matching the data in the two files to arrange it into B3
the way it filters and arranges the data i can figure out i reckon im just unsure on how to go about this initial idea
Save time doing menial administrative tasks for my work
also a personal project as Im trying to pick coding back up again since finishing my college course 2 years ago
ooh thats awesome. i wish you good luck in your journey
thank you <3
bumping this for anyone who sees the thread, il update and close the thread if i figure it out in the meantime <3
"by matching the data in the two files"
so if you had some data X and some data Y in file B1, then X and Z in file B2, you want file B3 to have X and Z?
so that's an intersection if you're familiar with set theory and venn diagrams
venn diagrams yes set theory no ๐คฃ
venn diagrams is all you'd need for this anyway
iv just had a quick look, looks like there is an intersection() method
would i be using this?
pretty much - yeah
you can also use the ampersand operator
one more question, what kind and volume of data are we talking about?
!e ```py
a = {1, 2, 5}
b = {5, 2, 3}
print(a & b)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
{2, 5}
okay, then it's pretty easy
no problem fitting it all in ram at the same time then ๐
so id use this type of method, to write the results into the file im wanting
you just need to organise your data into two sets and take the intersection (A and B), hence A & B
yeah im not doing anything on a large scale, its just very long time consuming admin work that kills my soul ๐คฃ
pretty much, yeah
bout 2 hours a day of organizing data manually
oof - feels bad
and i realised i can just make a script do it with some copypasted input files
funnily enough, there's a book called "automate the boring stuff with python"
iv been referencing that from time to time
understandable, those types of things are just begging to be automated
but iv found stackoverflow to be most helpful
mainly with the errors iv experienced, i have that shadow variable issue but it isnt causing any problems at the moment
so il sort that out once i have the entire process coded
steering back on track - is there anything else you need help with?
any errors, complications, logic errors?
no the intersection method tip should steer me in the right direction thank u both for your help <3
no problems reading in and wringing out files at least, right?
i did at first but i fixed that, it was an issue with not specifying the encoding
and you are doing so with a context manager (beginning the line with with) so that you don't need close()
yeah
btw not entirely relevant since this is a python discord, could this be done in java too
that was what i was taught in my course 2 years ago i kinda want to recreate it afterwards sometime in that langauge if thats possible
sure, but python is really perfect for this
yeah i saw it was gonna be used in my upcoming uni degree im starting so thought it would be a good place to start
python
i did a IT course at college that taught java for its programming classes, starting a part time mathematics degree which uses python
but yeah thank u both <3 il archive this thread if i can do that idk
you'll find many commonalities between many languages
you as op can type !close to close a help topic, otherwise it will automatically close after one hour of inactivity
good luck with your coding and you can always come back and open new help topics if there is anything more you are wandering about ๐
yes, a lot of typing (and reading, as it's a lot of code) with java
it's quite verbose
you'll probably find python much easier to read and write
and you'll probably be more productive in python as well
thank u again for yalls help <3 really appreciate it
but java is much more performant if you need raw performance
have a good night / day depending on timezone <33
otherwise python is mostly find for most tasks
for this scale all that really matters is ease of writing the code
credit where credit is due it's raining outside was the one that actually addressed the issue for this help topic
thank you and the same to you ๐
!close
!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.
