. . , (, event_dt_num) , Pandas ( , NaN ).
, . , , .
, -. , csv (Spark 2.0.0+) spark-csv ( 1.6 ):
df = (spark.read.format("csv").options(header="true")
.load("/path/tp/demo2016q1.csv"))
#
#
#
#
#
#
#
#
#
#
#
#
inferSchema="true" , . :
from pyspark.sql.types import StructType
schema = StructType.fromJson({'fields': [{'metadata': {},
'name': 'primaryid',
'nullable': True,
'type': 'integer'},
{'metadata': {}, 'name': 'caseid', 'nullable': True, 'type': 'integer'},
{'metadata': {}, 'name': 'caseversion', 'nullable': True, 'type': 'integer'},
{'metadata': {}, 'name': 'i_f_code', 'nullable': True, 'type': 'string'},
{'metadata': {},
'name': 'i_f_code_num',
'nullable': True,
'type': 'integer'},
{'metadata': {}, 'name': 'event_dt', 'nullable': True, 'type': 'integer'},
{'metadata': {}, 'name': 'event_dt_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'mfr_dt', 'nullable': True, 'type': 'integer'},
{'metadata': {}, 'name': 'mfr_dt_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'init_fda_dt', 'nullable': True, 'type': 'integer'},
{'metadata': {},
'name': 'init_fda_dt_num',
'nullable': True,
'type': 'string'},
{'metadata': {}, 'name': 'fda_dt', 'nullable': True, 'type': 'integer'},
{'metadata': {}, 'name': 'fda_dt_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'rept_cod', 'nullable': True, 'type': 'string'},
{'metadata': {},
'name': 'rept_cod_num',
'nullable': True,
'type': 'integer'},
{'metadata': {}, 'name': 'auth_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'mfr_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'mfr_sndr', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'lit_ref', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'age', 'nullable': True, 'type': 'double'},
{'metadata': {}, 'name': 'age_cod', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'age_grp', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'age_grp_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'sex', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'e_sub', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'wt', 'nullable': True, 'type': 'double'},
{'metadata': {}, 'name': 'wt_cod', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'rept_dt', 'nullable': True, 'type': 'integer'},
{'metadata': {}, 'name': 'rept_dt_num', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'to_mfr', 'nullable': True, 'type': 'string'},
{'metadata': {}, 'name': 'occp_cod', 'nullable': True, 'type': 'string'},
{'metadata': {},
'name': 'reporter_country',
'nullable': True,
'type': 'string'},
{'metadata': {}, 'name': 'occr_country', 'nullable': True, 'type': 'string'},
{'metadata': {},
'name': 'occp_cod_num',
'nullable': True,
'type': 'integer'}],
'type': 'struct'})
:
(spark.read.schema(schema).format("csv").options(header="true")
.load("/path/to/demo2016q1.csv"))