Compare string PANDAS Data Science

Asked

Viewed 231 times

0

I’m starting in this world of data science and my doubt how I can compare two string in the same column.

inserir a descrição da imagem aqui

I have a column [Investigation Type] that has 'Accident' and 'Incident' I wanted to compare the two with graphics and I’m not getting. how could I make this comparison with pandas?

  • I did not understand the question. What comparison would you like to make? Count the occurrences of Acidente and Incidente?

1 answer

0

If the comparison is to see the number of occurrences of each type, Acidente and Incidente, and plot a bar graph, it is possible to use the function hist of the pandas themselves:

df['Investigation Type'].hist()

But I particularly find the matplotlib graph more beautiful:

import matplotlib.pyplot as plt

x = df['Investigation_Type'].unique() #['Acidente', 'Incidente']
# Também é possível pegar valores específicos fazendo: x = ['Acidente', 'Incidente']
y = [df['Investigation_Type'].value_counts()[key] for key in x]

plt.bar(x, y)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.