For CSV format files, I would like to have one of the numbers in the line and What should I do to find a line with ◯ " and any number? It's my first time posting on StackOverflow and I don't know how to ask code questions at all. I want to reflect the condition of or, but it does not. I tried any and the following, but only the number of patient numbers with SY lines was printed as many as SY lines. There are two. The second one will be added I edited the code based on @oriiri's advice. I'm going to use the same code for example. If you write the congestion pattern and spontaneous fluorescence pattern continuously as follows, any() with
◯ が, but I could only create one of the numbers in
の <
and any with only the first number in
>
any.
Probably, or conditions are not reflected. if(((" " in" inline) and (any(["8847450" or "3625014" or "3625037" or "8831472") inline):
I thought it would be better not to give much information because it is a medical institution, but I will give it to you in moderation.
As an image, the objective is to output a patient number with a line with SY and a disease name of A, B, C, D or E on that line.I think I'm using or wrong. if("SY") and("A" or "B" or "C" or "D" or "E") inline:
if "SY" inline and ("8847450" or "3625014" or "3625037" or "8831472" or
"8847490" or "8849662" or "8837631" or "8837585" or "8842213" or "8841636" or "8830978"
or "8840886" or "8840626" or "3627007" or "3671002" or "8833933"
or "3623046" or "8840647" or "8845932" or "8841160" or "8847607" or "8847668" or "8849687"
or "8840659" or "8840661" or "8849884" or "8842886" or "8842298"
inline):
Overall Code
from os import O_EXLOCK
import pandas aspd
import numpy as np
import csv
# Loading Datasets
# f = pd.read_csv ('RECEIPTC.UKE', 'r', encoding = "shift-jis")
f=open("/Users/RECEIPTC.UKE", encoding="shift-jis")
# 'utf-8'
############################################################################
#
# Medical treatment #
############################################################################
# If SY line has 000000000
# There are if "SI" lines and "0000000000" lines
""""""""""""""""""""""""""""""""""""""""""
# spontaneous fluorescence
""""""""""""""""""""""""""""""""""""""""""
line_RE=False
line_SY = False
line_SI=False
for line inf:
# Store and initialize patient name whenever RE appears
if 'RE' in line:
name = line.split(',') [13]
line_RE=True
line_SY = False
line_SI=False
# If SY2 (disease name) line is equal
if("SY") and("8847450" or "3625014" or "3625037" or "8831472" or
"8847490" or "8849662" or "8837631" or "8837585" or "8842213" or "8841636" or "8830978"
or "8840886" or "8840626" or "3627007" or "3671002" or "8833933"
or "3623046" or "8840647" or "8845932" or "8841160" or "8847607" or "8847668" or "8849687"
or "8840659" or "8840661" or "8849884" or "8846886" or "8842298") inline:
Line_SY = True#SY Appropriate Determination
print(name)
# spontaneous fluorescence 160199310
if ("SI" and "160199310") inline:
line_SI = True#SI as applicable
# print(name)
""""""""""""""""""""""""
#1879 4699 1221 4213 4687 3190 2982
#4125 3782 3189 4161 3128
""""""""""""""""""""""""
if not(line_SY) and line_SI:
# print(name)# Patient Name Output
""""""""""""""""""""""""
#1879 4699 1221 4213 4687 3190 2982
#4125 3782 3189 4161 3128
""""""""""""""""""""""""
line_RE=False
line_SY = False
line_SI=False
# initialization
#break (when there is a break, nothing comes out)
First point
Does the same patient number appear in the code below because there are two numbers that fit the number in the corresponding id_list, so is there also two patient numbers?
For example, > It's a part of 2344 had two 8831472 in the disease name (the number included in the SY line) (because when you name a disease, it becomes a right-left isometric code + a disease name). For example, the number means right, 8831472 or the number means left, 8831472. One patient will have two 8831472 in multiple SY lines. So if I output it, will I get two 2344s?
But 2542 didn't have the same disease name number. Is this because there are two numbers in the id_list? For example, "8847450" and "3625014" were available.#if SY2 (disease name) line has etc.
id_list=["8847450", "3625014", "3625037", "8831472",
"8847490","8849662","8837631","8837585","8842213","8841636","8830978"
,"8840886","8840626","3627007","3671002","8833933"
,"3623046","8840647","8845932","8841160","8847607","8847668","8849687"
,"8840659","8840661","8849884","8846886","8842298"]
if "SY" inline and any(id inline for id in id_list):
Line_SY = True#SY Appropriate Determination
# print(name)
#8831472 There are 30 cases, but they don't come out.
""""""""""""""""""""""""
#1879
#3128 3816 4699 3218 2496 4213 4689
#4687 4626 3870 > 2344 2344 (8831472)
# >4669 4669(?)
#3154 3190 4499 199 3074 2982 4108
# >2542 2542(?)
#4125 3052
# >3879 3879 (#8831472)
#3782
# >3189 3189(?)
#4488
# >4161 4161 (8834556)
#2987 3128
""""""""""""""""""""""""
Second point
When the code is spontaneous fluorescence only, nothing is output
I put in a break, but it doesn't seem meaningful############################################################################
#
medical # #
############################################################################
# ## ## UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING congestion) TO !!!!) TO UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING UTILIZING ## ## ##
line_RE = False
line_SY = False
line_SI = False
for line in f:
# RE is to store patient names every time they come up and an initialization
if 'RE' in line:
name = line.split(',')[13]
line_RE = True
line_SY = False
line_SI = False
# Prefer iproute2 Y2 (disease) or the like is (JEAC 4111 perspective and 37), etc.
id_list = ["3789001","3784001", "8831705","8844716",
"3673004","8847774","3785017","3795003","3795019","8026003","8845049",
"8845078","8838065","3785007","3785014","3675013"]
if "SY" in line and any(id in line for id in id_list):
Line_SY = True#SY Appropriate Determination
# print(name)
#4357 4358
#3784001 → 5 cases
#1827 4338 4321 4341 4357 4319 567 4358 387
if('SI' and '160083810') inline:
line_SI = True#SI as applicable
# print(name)
#4338 4321
#4341 4357 4319 4358 387
# There are if "SI" lines and "160083810" (congestion)
if not(line_SY) and line_SI:
# print(name)# Patient Name Output
#4338 4321 4341 4319 387
line_RE=False
line_SY = False
line_SI=False
# initialization
break
""""""""""""""""""""""""""""""""""""""""""
# spontaneous fluorescence
""""""""""""""""""""""""""""""""""""""""""
line_RE=False
line_SY = False
line_SI=False
for line inf:
# Store and initialize patient name whenever RE appears
if 'RE' in line:
name = line.split(',') [13]
line_RE=True
line_SY = False
line_SI=False
# If SY2 (disease name) line is equal
id_list=["8847450", "3625014", "3625037", "8831472",
"8847490","8849662","8837631","8837585","8842213","8841636","8830978"
,"8840886","8840626","3627007","3671002","8833933"
,"3623046","8840647","8845932","8841160","8847607","8847668","8849687"
,"8840659","8840661","8849884","8846886","8842298"]
if "SY" inline and any(id inline for id in id_list):
Line_SY = True#SY Appropriate Determination
# print(name)
#8831472 There are 30 cases, but they don't come out.
""""""""""""""""""""""""
#1879
#3128 3816 4699 3218 2496 4213 4689
#4687 4626 3870 2344 2344 (8831472)
# 4669 4669 (?)
#3154 3190 4499 199 3074 2982 4108
# 2542 2542 (?)
#4125 3052
# 3879 3879 (#8831472)
#3782
# 3189 3189 (?)
#4488
# 4161 4161 (8834556)
#2987 3128
""""""""""""""""""""""""
# spontaneous fluorescence 160199310
if("SI" and "160199310") in line:
hydra Winksite Zuckerberg = # corresponding SI determined of the TCP_SN I
print(name)
""""""""""""""""""""""""
#1879 4699 1221 4213 4687 3190 2982
#4125 3782 3189 4161 3128
""""""""""""""""""""""""
if not (line_SY) and line_SI :
# Sprint (name ) # a patient's name shutsuryoku
""""""""""""""""""""""""
# 1 only 214.
""""""""""""""""""""""""
#1879 4699 1221 4213 4687 3190 2982
#4125 3782 3189 4161 3128
""""""""""""""""""""""""
line_RE = False
line_SY = False
line_SI = False
# initialization
break
# (There's another break and they won't be's nothing in it )
It may just be that I don't understand the problem well,
I think any() in Python will return True or False.
(Non-zero for numbers, or True for Boolean if any is in the list.)
Therefore, according to the code above,
any(["8847450" or "3625014" or "3625037" or "8831472" ]
This part only returns True, resulting in
if("◯ "" inline) and (True inline)):
So I don't think it matches what I want to look into.
So if you know all the numbers,
Easy
OKIDs=["8847450", "3625014", "3625037", "8831472" ]
If ("◯ "" in line):
for id in OKIDs:
if id inline:
XXXXXX<- What ABCDF wants to do
I think it will be all right if
However, in this case, a similar number such as "88474501" exists on the line.
So, if you want to look into more detailed conditions,
"From the "" の <"" and ""specific numbers"" are extracted first from the line, and then
"
I think it's better to make it if statement.
I thought it would be easier to check if there was test data, so I looked it up a little and found it on the following site.
Download Information|Social Insurance Medical Fee Payment Fund
I downloaded the following data from here.
CSV information of electronic receipt and sample data of electronic receipt data
April 2nd year of the Showa era Medical treatment: 18 cases (ZIP: 930KB)
Remove the CSV file that is inside and rename it to RECEIPTC.UKE
.Load using Pandas read_csv().
import pandas as pd
df=pd.read_csv('RECEIPTC.UKE', 'r', encoding="shift-jis")
:
pandas.errors.ParserError: Error tokenizing data.Cerror: Expected 1 fields inline 123, saw2
………Oh my gosh, an error has occurred.The reason is the uneven number of columns.I can't help it, so I'll change the reading.
import pandas as pd
df=pd.read_csv('RECEIPTC.UKE', sep='\n', header=None, prefix='X', encoding="shift-jis")
df = df.X0.str.split(',',expand=True).fillna('
print(df)
0 1 2 3 4 ... 46 47 48 49 50
0 2 10 MN 910000041 ...
1 1 2 0 IR 1 ...
2 1 30 RE 9...
3 1 40 HO 06132013 ...
4 1 50 GR 09 ...
... .. .. .. .. ... ... .. .. .. .. ..
998 2 11 1 EX...
999 2 121 EX...
10002 130 RC Ver00001bd39c87bcce59458fa26da72e53ef72c...
1001 2 141 RC Ver000017f93222 added 463b40f8281c6d95 aadcd37d7ca44 ...
1002
[1003 rows x 51 columns]
The purpose of the image is to print a patient number with a line with SY and a disease name of A, B, C, D or E on that line.
#Number of lines with identifier SY
print(len(df[df[3]=='SY']))
242
# List of Injury and Disease Information You Want to Extract
SVs= ("1509003", "8841698", "2500015", "1509003", "8842624")
# extraction conditional expression
condition=(df[3]=='SY')&(df[4].isin(SVs))
# Extract (I don't know what row the patient number is in, so I'll show you the whole thing)
print(df[condition])
#
0 1 2 3 4 5 6 7 8 9 ...
5 1 60 SY 1509003 20151102 101 ...
6 1 70 SY 8841698 20151110 1 ...
7 1 80 SY 2500015 20151110 1 ...
8 1 90 SY 1509003 20151217 1804801 ...
91 100 SY 8842624 20151222 101 ...
3101 80 SY 2500015 201901211 ...
546 180 SY 2500015 201901211 ...
761 190 SY 8841698 201908011 ...
806 1 100 SY 8842624 201212031 ...
877 121 0 SY 2500015 201904241 ...
[10 rows x 51 columns]
If the line
variable is a string type, the in
operation returns whether or not the string is included in the boolean.
(Bool: True or False)
Note: https://docs.python.org/ja/3/reference/expressions.html#membership-test-operations
The and
operators and or
operators also handle (mostly) Bool, and the result is Bool.
Note: https://docs.python.org/ja/3/reference/expressions.html#boolean-operations
Therefore, you can use the generator formula to describe whether or not one of the multiple strings is included.
id_list=["8847450", "3625014", "3625037", "8831472", "8847490",
"8849662", "8837631", "8837585", "8842213", "8841636", "8830978",
"8840886", "8840626", "3627007", "3671002", "8833933", "3623046",
"8840647", "8845932", "8841160", "8847607", "8847668", "8849687",
"8840659", "8840661", "8849884", "8846886", "8842298"]
line = 'abcd8846886efg'
if any(id inline for id in id_list):
pass# If any of the characters are included, the action of the .
# This is what it looks like to judge the conditions of a question.
if "SY" in line and any(id in line for id in id_list):
pass#
If you use pandas, it will be a different conditional expression
You can get a list of whether or not the number string is included using the list inclusion notation, and any()
can determine the resulting list of Boles
bool_list=[id inline for id in id_list]
print(any(bool_list))
The generator expression is used as a generator instead of the list
and both results are the same in this case (although the behavior is slightly different).
As mentioned above, the and
operators and or
operators specify (mostly) Bool, and if you specify a string, it will be true unless the length = 0. In this case, the result will be the value specified later and will not be the intended decision
#Spontaneous Fluorescence 160199310
# if ("SI" and "160199310") inline:
# This decision is made in parentheses first, and only useless operations are made with the and operator and string.
# (Probably) a statement like this.
for line in ['SI', '160199310', '160199310 SIO']:
if "SI" inline and "160199310" inline:
print(line)
Also, the break
statement is outside the indentation of the if statement, so it is done unconditionally
© 2025 OneMinuteCode. All rights reserved.