Celeste Wilson

Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Nov 9, 2023 15:25
this is the block in the content I want to replace and make duplicates of with the iterations into a separate text file. I can then paste it in
Nov 9, 2023 15:21
LOL
Nov 9, 2023 15:21
its a very old fortran software (industry). Forced to use it. Trying to make it work cause I'm not pasting 12,585 times.
Nov 9, 2023 15:20
hahahahah
Nov 9, 2023 15:20
why aren't there emojis
Nov 9, 2023 15:18
This is from a different software, I have 12,585 .00t files in a folder (same folder). I need it to iterate through the list that is in a csv and increase boundary_1 each time (to boundary_2,3,4,...), increase priority=1.000000000000 by 1 each time, and change the name of triangulation='C:\Vulcan\GStrike\DeswikVulcanExport\blank_94_repair.00t' to the new name that is in column 1 in the csv.
Nov 9, 2023 15:16
BEGIN$DEF boundary_1
 condition=' '
 inversion='None'
 priority=1.000000000000
 projection='Z'
 triangulation='C:\Vulcan\GStrike\DeswikVulcanExport\blank_94_repair.00t'
 value='1'
 variable='p_mined_23q4'
END$DEF boundary_1
Nov 9, 2023 15:13
hhahhahahahhaahha my thoughts exactly except its down again hahahahhahah
Nov 9, 2023 15:07
What's the easiest way to replace a few words in a block of text looping through a csv row by row? I've googled and looked around and I keep finding "how to replace items in csv". I want to replace words in a block of text.
Aug 2, 2023 18:27
@MisterMiyagi Your idea is what helped me, thank you!
Aug 2, 2023 18:26
Output:
./Domains.tri/Pop01_06082023.00t : 1 : p1
./Domains.tri/Pop02_06082023.00t : 2 : p2
./Domains.tri/Pop03_06082023.00t : 3 : p3
./Domains.tri/Pop06_06082023.00t : 6 : p6
./Domains.tri/Pop07_06082023.00t : 7 : p7
./Domains.tri/Pop08_06082023.00t : 8 : p8
./Domains.tri/Pop09_06082023.00t : 9 : p9
./Domains.tri/Pop10_06082023.00t : 10 : p10
./Domains.tri/Pop11_06082023.00t : 11 : p11
./Domains.tri/Pop12_06082023.00t : 12 : p12
./Domains.tri/Pop13_06082023.00t : 13 : p13
Aug 2, 2023 18:26
val2 = [1,2,3,4,5,6,7,8,9,10,11]
# Check assigned code for each triangulation
for itri in range(len(triangulations)):
    print("Current flagvalue:", flagvalue[itri])  # Print current flagvalue for this iteration
    print("triangulations:", triangulations[itri])
    print("estdom:", estdom_name)
    for fl,val,x in zip(triangulations[itri],flagvalue[itri],val2):
        #print("val:", val)
        print(fl+' : {} : '.format(val) + estdom_name[x-1])
Aug 2, 2023 18:26
Wait I think I got it
Aug 2, 2023 18:21
so what its doing is val = 1--> estdom_name[1-1] = 1st item in estdom_name, etc. That would be fine but I don't have a 4 or a 5 so it gets to those and puts val = 6 --> estdom_name[6-1] = which is the p8 when what I want is p6. I understand what it is doing and why I get the error just not how to force it to give me what I want LOL!
Aug 2, 2023 18:04
but val is in flagvalue which is flagvalue = [[1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13]]
Aug 2, 2023 16:51
Still gives an error saying:
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-96-e2c25e902751> in <module>()
      7     for fl,val,x in zip(triangulations[itri],flagvalue[itri], estdom_name):
      8         #print("val:", val)
----> 9         print(fl+' : {} : '.format(val) + estdom_name[val-1])

IndexError: list index out of range
Aug 2, 2023 16:44
Inputs:
estdom_name = ['p1', 'p2', 'p3', 'p6', 'p7', 'p8', 'p9', 'p10', 'p11', 'p12', 'p13']
triangulations = [['./Domains.tri/Pop01_06082023.00t',
  './Domains.tri/Pop02_06082023.00t',
  './Domains.tri/Pop03_06082023.00t',
  './Domains.tri/Pop06_06082023.00t',
  './Domains.tri/Pop07_06082023.00t',
  './Domains.tri/Pop08_06082023.00t',
  './Domains.tri/Pop09_06082023.00t',
  './Domains.tri/Pop10_06082023.00t',
  './Domains.tri/Pop11_06082023.00t',
  './Domains.tri/Pop12_06082023.00t',
  './Domains.tri/Pop13_06082023.00t']]
Mar 9, 2023 15:56
let me try the csv module
Mar 9, 2023 15:56
its a file that has extension .csv
Mar 9, 2023 15:42
the only position 15 I know is by counting characters/spaces from start to that or if it is meaning column or row. I don't think that's what it is. I have been googling. Is there some debugging call I can use that will search for it and show me?
Mar 9, 2023 15:41
When I'm loading a csv, its telling me there is something off in the file somewhere (weird character, etc.) I got it to load using this encoding='ISO 8859-1' but I want to know how to find where it is. The error message is : UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 15: invalid start byte
Feb 1, 2023 14:12
Does anyone here use SQL or pandasql
Dec 27, 2022 23:06
I get those: one at a time, multiple at a time...the issue that was messing me up is I was getting double brackets with append and single with extend
Dec 27, 2022 23:05
thank you
Dec 27, 2022 23:05
that was the piece I was missing
Dec 27, 2022 23:05
and putting flagvalue[0] is what gets me to have it "append" the 13 with the rest inside the double brackets
 
Feb 15, 2023 19:06
so for each variable don't look at what is missing in the other variables, run for 1 column then the next then the next
Feb 15, 2023 19:06
yeah for each variable it will have to do it for each to fill it, not use other rows to decide if it fills. Each is mutually exclusive
Feb 15, 2023 00:04
does that make sense?
Feb 15, 2023 00:04
cause the 5+5+5 = 15 = 125-140 = 15
Feb 15, 2023 00:04
MRC-15 rows 19, 20, 21 are a match with 125-140 of Y
Feb 15, 2023 00:04
MRC-15 row 18 is a match with 120-125 of Y
Feb 15, 2023 00:03
MRC-17 rows 10, 11 match with 430-440 of Y
Feb 15, 2023 00:03
MRC-17 rows 8, 9 are a match with 420-430 of Y
Feb 13, 2023 17:06
if I dont' run it, it shows all
Feb 13, 2023 17:06
ah I see... if I run the first code you put on the post, it shows remaining
Feb 13, 2023 16:43
oh is it showing the remaining missing?
Feb 13, 2023 16:37
Does it find any matches missing?
Feb 8, 2023 23:55
We trust df1 over df2 because we trust the 1 lab over the 2 lab. But... if we don't have the data from lab 1 we want the data from lab 2 (only if the sample size was the same size). If I take a sample and take a big and small sample from it (lengths From To) I won't get the same answer analytically. So that's why I'm trying to fill 1 with "same size" from 2 variable by variable for each test. Just in case that helps
Feb 8, 2023 23:55
but we would want to exclusively update. Just some background info since this is a chat and not public. the two datasets are analytical in a lab data.
Feb 8, 2023 22:52
k letme try this last piece
Feb 8, 2023 22:48
k I'm back, had a very long meeting ugh
Feb 8, 2023 16:46
let me look, I have a meeting. I'll be back later :) sorry and thank you for all the help! I work in the mining industry so only been using python about 10 years but normally whats needed is already built and this is not :(
Feb 8, 2023 15:54
ranges = df2.assign(
   Range=list(map(lambda row:
         list(range(row[0], row[1], 5)),
         df2[["From", "To"]].to_numpy()))
).explode("Range")

matches = (
   df1.merge(
      ranges,
      left_on=["ID", "From"],
      right_on=["ID", "Range"],
      how="left")
)

# Keep only repeating -99 sequences
matches1 = matches.loc[
   (matches["Q_x"] == -99) &
   ((matches["Q_x"].shift(-1) == -99) | (matches["Q_x"].shift(+1) == -99)),
]
matches2 = matches.loc[
   (matches["RM_x"] == -99) &
   ((matches["RM_x"].shift(-1) == -99) | (matches["RM_x"].shift(+1) == -99)),
Feb 8, 2023 15:54
I tried what you had and expanded it to all 3 variables and it looks like it works on the first variable "Q" but not on RM, RQ. It's just filling those in and maybe I didn't expand right
Feb 8, 2023 15:54
Hi @jqurious, it said to move this discussion to chat
Feb 8, 2023 15:53
its already in there for smaller. For RM column you'll see MRC-17 at 400-410 and 415-420 it wants to replace but we can't replace since df1 (x) has a value in the middle at 410-415.
Feb 8, 2023 15:53
Yes, the small interval in x I don't want to replace unless it has an equal interval in y. I did figure out the script to add the unmatched IDs back in but if you have a more efficient way to add it into this, I'm all ears. I think I pasted it at the end of my question with code. Thank you so much for all the help!
Feb 8, 2023 15:53
ok I tried it and added a change column for each variable. It's almost all the way there. Now I only want to replace if I have the same length of replacement in each. For instance, if df1 (x) is missing in MRC-17 from 420-430, I see I have a 420-430 that matches in df2 (y) so I want to replace but in MRC-17 from 400-405 and 405-410 RM_x is missing, I don't have 400-410 interval in df2 (y), I have a 400-420 but I want it to equal the run of missing, if that makes sense? I don't want to replace 10 ft with 20 ft. Does that make sense?
Feb 8, 2023 15:53
This is exactly what I was trying to convey/ask! The rest, do I put if Change = True then Q_x = Q_y, otherwise use Q_x (same for all variables, of course in python language, not Excel)