I am using a CSV file as input to and generate JSON format file to feed into kafka topic
df = pd.read_csv(csv_file, delimiter=",",
dtype={'E': 'S10', 'C': 'S10', 'Date': 'S10', 'TimeCode': 'S10',
'Workrule': 'S10'})
common.time_calc(df) #time_calc is the function from a
df = df.drop(['Workrule'], axis=1)
On the function I have
def time_calc(df_entry):
if (df_entry['TimeCode'] == 'R') and (df_entry['Workrule'] == 'C'):
df_entry['TimeCode'] = 'A'
if df_entry['TimeCode'] in ['O', 'L']:
df_entry['TimeCode'] = 'O'
and I am getting
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I have tried modifying the code as
if (df_entry['TimeCode'] == 'R') & (df_entry['Workrule'] == 'C'):
df_entry['TimeCode'] = 'A'
but still get the same error.
Added the following and was able to post now. thanks!
json_data = df.to_json(orient='records')
json_input = '{"value":' + json_data + '}'
decodedJson = json.loads(json_input)
for entry in decodedJson['value']:
common.time_calc(entry)
del entry['Workrule']