I have the following JSON file named as info.Json:
{
"jobs": [
{
"type": "Account",
"min": 5,
"max": 15,
"arguments": {
"inix": 48,
"load": "3.081579e+07",
"overload": "6.508037e+07"
},
"attributes": {
"name": "emp_1",
"priority_type": "low",
"dependency": "-"
}
},
{
"type": "detect",
"min": 5,
"max": 13,
"arguments": {
"inix": 748,
"load": "3.081579e+07",
"overload": "6.508037e+07"
},
"attributes": {
"name": "emp_2",
"priority_type": "high",
"dependency": "-"
}
},
{
"type": "Account",
"min": 5,
"max": 15,
"arguments": {
"inix": 48,
"load": "3.081579e+07",
"overload": "6.508037e+07"
},
"attributes": {
"name": "emp_3",
"priority_type": "low",
"dependency": "-"
}
}
]
}
I have tried to write the following python code, to take a value of dependency from csv file and write it rather than the "-". What I need is just replace each occaurence of "-" with job_dependency value which read from csv file.
path='/load/statistics.csv'
for repeat in range(repeats):
job_statistics = pd.read_csv(path)
job_dependency = job_statistics['dependency'][repeat]
print(job_exe_time)
temp["attributes"]["dependency"]= f"{job_dependency}"
with open("data_inv_jobs50.json", "wt") as fout:
for line in file_data:
fout.write(line.replace("-","{job_exe_time}"))
I need to replace the value of "dependency": "-" with "dependency": "value from csv" , but my code above not working well .. any suggestion ?
2
Answers
I came up with this:
Here I asssumed there was only one dependency value. In this case, you can (and should) retrieve this value first, before entering the loop you will use to modify the content of your file.
You can use the following script to replace the ‘-‘ value with your desired value.