Convert string to int using weave

I have a string column which contains values in the format : “Metric: Metric_Value”. I want to extract Metric_Value from the column and plot it as histogram. I am able to extract the Metric_Value using findAll(“\d+”) but it is extracted as a string. How can I convert this to a number? StringHistogram plot does not work for me in this case since it loses the oridnal information stored in the corresponding int.

Hello @sarda014 ,

To convert the extracted string to a number, you can use Python’s built-in int() or float() functions. Here’s an example:

# Assuming you have a list of strings
str_values = ["1", "2", "3"]

# Convert to integers
int_values = [int(val) for val in str_values]

# Now you can log a histogram
data = [[val] for val in int_values]
table = wandb.Table(data=data, columns=["values"])
wandb.log({'my_histogram': wandb.plot.histogram(table, "values", title="Histogram")})

This will convert your string values to integers and then log them as a histogram in Weights & Biases.

Please note that this code assumes that all your string values can be converted to integers. If some of your values are not integers, you might want to use float() instead of int(), or add error handling to deal with exceptions.

Hi @sarda014 , since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.