-1

Let us say that we have a column with the following values:

Apple, Mango, Orange, 123, 987, Guava, 01/01/2020

python recognizes this column as an "object" data type automatically. I have been given a task to count the number of data types in a single column. For a human eye, it is evident that there are 3 data types in the above column values: string, int, date. However, I am unable to come up with a code which could do this segregation. Looking forward to the guidance! Thank you!

petezurich
  • 9,280
  • 9
  • 43
  • 57
Vinay
  • 1
  • 1
    Welcome on stackoverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and how to give a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). That way you can help others to help you! – Kevin Cazelles Feb 21 '20 at 21:11
  • I think this is what you are looking for: https://stackoverflow.com/questions/22199741/identifying-the-data-type-of-an-input – Jeff Feb 21 '20 at 21:14

2 Answers2

0

Could you provide some code on what you have attempted? How are you setting up the data structure? Is it an m * n matrix where each column would have a common j in data[i][j]? In that case, it seems like you could just iterate over the matrix rows for the column and use the type() method.

Not knowing a bit more about your setup makes it difficult to provide a solution. Generally data in columns is of a common type.

Justin B
  • 51
  • 5
0

If your data is in the form of a list, you could always do list(map(type, list_name)) to return a list of types.

AmphotericLewisAcid
  • 1,824
  • 9
  • 26