3
DRIVER’S NAME,LICENSE,PH NUMBER,DOB,HIRE DAY CARLOS ARELLANO ,A645-100-63-345-0,(786) 424 1186,24/09/1959,08/01/2008 ISAEL PENA,P515-400-76 346-0,(305) 915 9316,25/09/1972,27/11/2010 YUSEL GONZALEZ ,G524-960-78-013-0,(786 ) 616- 1023,12/01/1974,25/08/2012 JESUS RAMOS ,R523-421-79-409-0,(352) 223-7929,08/11/1975,12/07/2012 DAVID GOLBOURNE ,G416-164-71-058-1,( 786 ) 251-7144,17/02/1967,06/09/2012 ,,,, ,,,, 

i have csv file like this when i am reading this file python gives "string" as a data-type how i can check each column data type using csv library

2
  • 1
    Can you post expected output? Commented Jul 26, 2018 at 7:20
  • 1
    Yes,Please see @Rakesh Commented Jul 26, 2018 at 7:24

3 Answers 3

3
import pandas as pd out = pd.read_cvs('./path_to_csv') out['LICENSE'] 

returns

0 A645-100-63-345-0 1 P515-400-76 346-0 2 G524-960-78-013-0 3 R523-421-79-409-0 4 G416-164-71-058-1 Name: LICENSE, dtype: object 

as required

If you want a dictionary:

dict(out) 

gives you

 {'DRIVER’S NAME': 0 CARLOS ARELLANO 1 ISAEL PENA 2 YUSEL GONZALEZ 3 JESUS RAMOS 4 DAVID GOLBOURNE Name: DRIVER’S NAME, dtype: object, 'LICENSE': 0 A645-100-63-345-0 1 P515-400-76 346-0 2 G524-960-78-013-0 3 R523-421-79-409-0 4 G416-164-71-058-1 Name: LICENSE, dtype: object, 'PH NUMBER': 0 (786) 424 1186 1 (305) 915 9316 2 (786 ) 616- 1023 3 (352) 223-7929 4 ( 786 ) 251-7144 Name: PH NUMBER, dtype: object, 'DOB': 0 24/09/1959 1 25/09/1972 2 12/01/1974 3 08/11/1975 4 17/02/1967 Name: DOB, dtype: object, 'HIRE DAY ': 0 08/01/2008 1 27/11/2010 2 25/08/2012 3 12/07/2012 4 06/09/2012 Name: HIRE DAY , dtype: object} 

as by your prefered output

Sign up to request clarification or add additional context in comments.

Comments

3

You can use pandas library to determine csv data type.

You can do something like this:

import pandas as pd df = pd.read_csv('your_csv_file.csv', nrows=2) for dtype in df.dtypes.iteritems(): print(dtype) 

Comments

2

One of the simplest is:

df.info() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.