Ask Your Question
4

How can you replace the hyphen character in a column of a data frame with a zero?

asked 2023-06-14 00:36:46 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-14 00:45:01 +0000

ladyg gravatar image

You can replace the hyphen character in a column of a data frame with a zero using the str.replace() method in pandas. Here's an example:

Assuming your data frame is called df and the column with the hyphen character is called my_column, you can replace the hyphen with a zero using the following code:

df['my_column'] = df['my_column'].str.replace('-', '0')

This code will replace all occurrences of the hyphen character in the my_column column with a zero, and store the modified values back in the same column.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-14 00:36:46 +0000

Seen: 14 times

Last updated: Jun 14 '23