더북(TheBook)

5.1.1.6 스키마 정보 가져오기

printSchema 메서드를 사용해 서로 다른 방식으로 생성한 itPostsDFStructitPostsDFCase 스키마가 동일한지 확인해 보자. 또 DataFrameschema 필드를 사용해 StructType 객체로 정의된 스키마를 참조할 수도 있다.

이외에도 columnsdtypes 메서드로 DataFrame의 스키마 정보를 확인할 수 있다. columns 메서드는 칼럼 이름 목록을 반환하며, dtypes 메서드는 각 칼럼 이름과 타입으로 구성된 튜플 목록을 반환한다. itPostsDFCase DataFrame을 대상으로 두 메서드를 호출한 결과는 다음과 같다.

scala> itPostsDFCase.columns
res0: Array[String] = Array(commentCount, lastActivityDate, ownerUserId,
  body, score, creationDate, viewCount, title, tags, answerCount,
  acceptedAnswerId, postTypeId, id)
scala> itPostsDFStruct.dtypes
res1: Array[(String, String)] = Array((commentCount,IntegerType),
  (lastActivityDate,TimestampType), (ownerUserId,LongType),
  (body,StringType), (score,IntegerType), (creationDate,TimestampType),
  (viewCount,IntegerType), (title,StringType), (tags,StringType),
  (answerCount,IntegerType), (acceptedAnswerId,LongType),
  (postTypeId,LongType), (id,LongType))
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.