there is data is store in a data frame and i use the fallowing code for result.
import pandas as pd
import numpy as np
import json
Data1 = 'Data/lab_202210181540.csv'
############### For Data 1 ####################
data_frame = pd.read_csv(Data1)
data_frame['data'] = data_frame['data'].apply(json.loads)
data_frame = data_frame.rename(columns={'id': 'Sr#'})
data_frame = data_frame.join(pd.json_normalize(data_frame['data']))
select_data = data_frame[['serializer']]
select_data['serializer'] = select_data['serializer'].apply(lambda x: json.loads(x) if pd.notnull(x) else np.nan)
final_select_data = select_data.join(pd.json_normalize(select_data.pop('serializer')))
result = final_select_data['Analyte_line']
df = pd.DataFrame(result)
for i in range(len(df['Analyte_line'])):
for arr in range(df['Analyte_line'][i]):
if arr[0] in ['Urea', 'Rapid Malaria']:
df[arr[0]][i] = "".join(map(lambda x: str(x), arr[1:]))
but there is error show which i unable to remove .
for arr in range(df['Analyte_line'][i]):
TypeError: 'float' object cannot be interpreted as an integer
how to remove this error. my expecting result look like this table as a simple.
| Patient_ID | Urea | Creatinine | Uric Acid | SGOT |
|---|---|---|---|---|
| KYN059AQP | 3.0,3 | 3.0,3 | 3.0,3 | - |
| KQT767JLU | - | - | - | 6.0 |
The data which store in my data frame like this.
the fallowing data is just an example
Patient_ID,Analyte_line
KYN059AQP,"[['Urea', 3.0, '3', ''], ['Creatinine', 3.0, '3', ''], ['Uric Acid', 3.0, '3', '']]"
KQT767JLU,"[['Total Protein', '', '6', ''], ['Albumin', '', '6', ''], ['Globulin', '', '4', ''], ['Total Bilirubin', '', '6', ''], ['Direct Bilirubin', '', '4', ''], ['Indirect Bilirubin', '', '4', ''], ['Alkaline Phosphatase', '', '4', ''], ['SGPT', '', '5', ''], ['SGOT', '', '5', ''], ['Gamma GT', '', '5', ''], ['AG Ratio', '', '4', '']]"
PWV009AGQ,"[['HGB', '', '18', ''], ['RBC', '', '1', ''], ['HCT', '', '2', ''], ['MCV', '', '3', ''], ['MCH', '', '3', ''], ['MCHC', '', '3', ''], ['RDWcv', '', '2', ''], ['RDWsd', '', '3', ''], ['WBC', '', '4', ''], ['NEU', '', '5', ''], ['LYM', '', '6', ''], ['MON', '', '', ''], ['BAS', '', '', ''], ['EO', '', '', ''], ['NEU%', '', '', ''], ['LYM%', '', '', ''], ['MON%', '', '', ''], ['EO%', '', '', ''], ['BAS%', '', '', ''], ['PLT', '', '170', ''], ['PCT', '', '3', ''], ['MPV', '', '', ''], ['PDWsd', '', '', ''], ['PDWcv', '', '', ''], ['ESR', '', '5', ''], ['GRA#', '', '', '']]"
PWV009AGQ,"[['Total Protein', '', '23', ''], ['Albumin', '', '2', ''], ['Globulin', '', '2', ''], ['Total Bilirubin', '', '2', ''], ['Direct Bilirubin', 2.0, '', ''], ['Indirect Bilirubin', 2.0, '', ''], ['Alkaline Phosphatase', '', '3', ''], ['SGPT', 1.0, '', ''], ['SGOT', '', '4', ''], ['Gamma GT', 33.0, '31', ''], ['AG Ratio', '', '2', '']]"
rangefunction requires anintegeras the boundary limit. If you will passfloatthen it will throw an error. Basically, you need to convertfloattointand then use it inrange. WHY? Because numbers are continuous in nature if you give float what will be executed < layman explanation.