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
,,,,
,,,,
当我阅读此文件时,我有这样的csv文件python给出“字符串” 作为数据类型,我如何使用csv库检查每个列的数据类型
答案 0 :(得分:1)
您可以使用pandas库确定csv数据类型。
您可以执行以下操作:
import pandas as pd
df = pd.read_csv('your_csv_file.csv', nrows=2)
for dtype in df.dtypes.iteritems():
print(dtype)
答案 1 :(得分:1)
import pandas as pd
out = pd.read_cvs('./path_to_csv')
out['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
根据需要
如果您想要字典:
dict(out)
给你
{'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}
根据您的首选输出
答案 2 :(得分:1)
最简单的方法之一是:
df.info()