2017-12-13 29 views
0

pd_dfというpandasデータフレームがあります。以下はデータ型です。sparkはpandas dateの時刻データ型をbigintに変換します

pd_df.dtypes 


id     int64 
TEST_TIME    datetime64[ns] 
status    object 
Pkg     object 
test_type    object 
test_name    object 
test_id    int64 
test_value   float64 
test_times   int64 
desc     object 
test_source   object 
GP     float64 
dtype: object 

は今、私はこのpd_dfsparkデータフレームに変換します。

私は以下のように行っています。

spark_df = sqlContext.createDataFrame(pd_df) 

spark_dfを正常に作成できました。しかし、データタイプが私の要求に合っていません。

火花データフレームの必須データタイプ。私が得たもの

DataFrame[id: int, test_time: timestamp, status: string, pkg: string, test_type: string, test_name: string, test_id: int, test_value: double, test_times: int, desc: string, test_source: string, GP: double] 

spark_df = sqlContext.createDataFrame(pd_df).withColumn('TEST_TIME1', unix_timestamp(col('TEST_TIME').cast("string"), "MM-dd-yyyy hh mm ss").cast("timestamp")).drop('TEST_TIME') 

また、「MM-DD-YYYY HH MMを置き換え、どのように私は

+0

データのサンプルを投稿してください – desertnaut

答えて

1

試しをしたい結果を得ることができ

DataFrame[id: bigint, test_time: bigint, status: string, pkg: string, test_type: string, test_name: string, test_id: bigint, test_value: double, test_times: bigint, desc: string, test_source: string, GP: double] 

を下回っていますss "をタイムスタンプの形式に変換します。あなたのタイムスタンプが2017年12月1日の12012017の場合、フォーマットは "mmddyyyy"になります

+0

あなたのコードをフォーマットしてください... – desertnaut

+0

@Vinoth Chinnasamyあなたのコードを試しました例外は、データ型の不一致のために 'unixtimestamp(TEST_TIME、MM-dd-yyyy hh mm ss)'を解決できません:引数1は(文字列または日付またはタイムスタンプ)型を必要としますが、 'pyspark.sql.utils.AnalysisException: TEST_TIME 'はbigint型です; "' – User12345

+0

私の答えが更新され、コードがフォーマットされました。 –

関連する問題