DataFrame 은 행과 열이 있는 데이터 테이블을 나타내며, DataFrame 개념은 어떤 프로그래밍 언어에서도 변하지 않지만 Spark 와 Pandas 의 DataFrame 은 상당히 다르다. 이 글에서는 Spark DataFrame과 Pandas DataFra,e의 차이점을 알아보려고 합니다.
Pandas DataFrame
Panda는 NumPy 라이브러리를 기반으로 하는 오픈 소스 Python 라이브러리입니다. 다양한 데이터 구조와 연산을 사용하여 수치 데이터와 시계열을 조작할 수 있는 Python 패키지입니다. 주로 데이터 가져오기 및 분석을 상당히 쉽게 하기 위해 사용됩니다. Panda DataFrame은 레이블이 지정된 축(행 및 열)을 가진 잠재적으로 이질적인 2차원 크기 가변 표 형식 데이터 구조입니다.데이터, 행 및 열은 Panda DataFrame의 세 가지 주요 구성 요소입니다.
장점:
- Panda Dataframe은 인덱싱, 이름 변경, 정렬, 데이터 프레임 병합 등의 데이터 조작이 가능합니다.
- Panda를 사용하여 열을 업데이트, 추가 및 삭제할 수 있습니다.
- Panda Dataframe은 여러 파일 형식을 지원합니다.
- 내장된 기능으로 인해 처리 시간이 너무 깁니다. (-> 이게 장점??)
단점:
- 거대한 데이터 세트를 사용하면 조작이 복잡해집니다.
- 조작 중에는 처리 시간이 느려질 수 있습니다.
Spark DataFrame
Spark는 클러스터 컴퓨팅용 시스템입니다. 다른 클러스터 컴퓨팅 시스템(예: Hadoop)과 비교했을 때 속도가 더 빠릅니다. Python, Scala 및 Java의 고급 API를 갖추고 있습니다. Spark에서는 병렬 작업을 쓰는 것이 간단합니다. Spark는 현재 가장 활발한 Apache 프로젝트로 다수의 데이터셋을 처리하고 있습니다. Spark는 Scala로 작성되며 Python, Scala, Java 및 R에서 API를 제공합니다. Spark에서 DataFrames는 행과 열로 구성된 분산 데이터 수집입니다. DataFrame의 각 열에는 이름과 유형이 지정됩니다.
장점:
- Spark는 대규모 데이터셋 조작에 사용하기 쉬운 API를 제공합니다.
- 'MAP'와 'reduce', 머신러닝(ML), 그래프 알고리즘, 스트리밍 데이터, SQL 쿼리 등을 지원한다.
- 스파크는 계산에 메모리 내(RAM)를 사용합니다.
- 병렬 애플리케이션을 개발할 수 있또록 80개의 High-level Operators 를 지원합니다.
단점:
- 자동 최적화 프로세스 없음
- 알고리즘이 거의 없습니다.
- 작은 파일 문제
Spark DataFrame과 Panda DataFrame의 차이점 표:
Spark DataFrame | Pandas DataFrame |
Spark Data Frame은 병렬화를 지원합니다. | Panda Data Frame은 병렬화를 지원하지 않습니다. |
Spark Data Frame에는 여러 노드가 있습니다. | Panda Data Frame에는 단일 노드가 있습니다. |
이 명령어는 작업이 수행될 때까지 작업이 실행되지 않음을 의미하는 Lazeagy Execution 뒤에 나옵니다. | 이 명령어는 작업이 즉시 실행된다는 의미인 Eager Execution에 이어 실행됩니다. |
Spark Data Frame은 불변입니다. | Panda Data Frame은 Mutable (변할 수 있는)입니다. |
복잡한 작업은 Panda Data Frame에 비해 수행하기가 어렵습니다. | Spark Data Frame에 비해 복잡한 작업은 수행하기가 더 쉽습니다. |
Spark DataFrame은 분산되므로 대량의 데이터를 처리하는 속도가 빨라집니다. | Panda DataFrame은 분산되지 않기 때문에 대량의 데이터에 대해 Panda DataFrame의 처리 속도가 느려집니다. |
sparkDataFrame.count()는 행 수를 반환합니다. | pandaDataFrame.count()는 각 열에 대해 null이 아닌 관찰 수를 반환합니다. |
Spark Data Frame은 확장 가능한 애플리케이션을 구축하는 데 매우 적합합니다. | Panda DataFrames는 확장 가능한 애플리케이션을 구축하는 데 사용할 수 없습니다. |
Spark Data Frame은 내결함성을 보장합니다. | Panda Data Frame은 내결함성을 보장하지 않습니다.우리는 그것을 확실히 하기 위해 우리 자신의 틀을 구현할 필요가 있다. |
Pandas 와 Spark 중에 선택
PySpark를 사용하는 것이 Panda에 비해 갖는 몇 가지 장점을 알아보겠습니다.
- 대량의 데이터셋을 사용하면 Pandas의 동작이 느려질 수 있지만 Spark에는 데이터를 조작하기 위한 API가 내장되어 있어 Pandas 보다 속도가 빠릅니다.
- Spark는 Pandas보다 구현이 용이하여 사용하기 쉬운 API를 갖추고 있습니다.
- Spark는 Python, Scala, Java 및 R을 지원합니다.
- Spark의 ANSI SQL 호환성.
- Spark는 계산에 메모리 내(RAM)를 사용합니다.
(원문)
Dataframe represents a table of data with rows and columns, Dataframe concepts never change in any Programming language, however, Spark Dataframe and Pandas Dataframe are quite different. In this article, we are going to see the difference between Spark dataframe and Pandas Dataframe.
Pandas DataFrame
Pandas is an open-source Python library based on the NumPy library. It’s a Python package that lets you manipulate numerical data and time series using a variety of data structures and operations. It is primarily used to make data import and analysis considerably easier. Pandas DataFrame is a potentially heterogeneous two-dimensional size-mutable tabular data structure with labeled axes (rows and columns). The data, rows, and columns are the three main components of a Pandas DataFrame.
Advantages:
- Pandas Dataframe able to Data Manipulation such as indexing, renaming, sorting, merging data frame.
- Updating, adding, and deleting columns are quite easier using Pandas.
- Pandas Dataframe supports multiple file formats
- Processing Time is too high due to the inbuilt function.
Disadvantages:
- Manipulation becomes complex while we use a Huge dataset.
- Processing time can be slow during manipulation.
Spark DataFrame
Spark is a system for cluster computing. When compared to other cluster computing systems (such as Hadoop), it is faster. It has Python, Scala, and Java high-level APIs. In Spark, writing parallel jobs is simple. Spark is the most active Apache project at the moment, processing a large number of datasets. Spark is written in Scala and provides API in Python, Scala, Java, and R. In Spark, DataFrames are distributed data collections that are organized into rows and columns. Each column in a DataFrame is given a name and a type.
Advantages:
- Spark carry easy to use API for operation large dataset.
- It not only supports ‘MAP’ and ‘reduce’, Machine learning (ML), Graph algorithms, Streaming data, SQL queries, etc.
- Spark uses in-memory(RAM) for computation.
- It offers 80 high-level operators to develop parallel applications.
Disadvantages:
- No automatic optimization process
- Very few Algorithms.
- Small Files Issue
Table of Difference between Spark DataFrame and Pandas DataFrame:
Spark DataFrame | Pandas DataFrame |
Spark DataFrame supports parallelization. | Pandas DataFrame does not support parallelization. |
Spark DataFrame has Multiple Nodes. | Pandas DataFrame has a Single Node. |
It follows Lazy Execution which means that a task is not executed until an action is performed. | It follows Eager Execution, which means task is executed immediately. |
Spark DataFrame is Immutable. | Pandas DataFrame is Mutable. |
Complex operations are difficult to perform as compared to Pandas DataFrame. | Complex operations are easier to perform as compared to Spark DataFrame. |
Spark DataFrame is distributed and hence processing in the Spark DataFrame is faster for a large amount of data. | Pandas DataFrame is not distributed and hence processing in the Pandas DataFrame will be slower for a large amount of data. |
sparkDataFrame.count() returns the number of rows. | pandasDataFrame.count() returns the number of non NA/null observations for each column. |
Spark DataFrames are excellent for building a scalable application. | Pandas DataFrames can’t be used to build a scalable application. |
Spark DataFrame assures fault tolerance. | Pandas DataFrame does not assure fault tolerance. We need to implement our own framework to assure it. |
Deciding Between Pandas and Spark
Let’s see few advantages of using PySpark over Pandas
- When we use a huge amount of datasets, then pandas can be slow to operate but the spark has an inbuilt API to operate data, which makes it faster than pandas.
- Easier to implement than pandas, Spark has easy to use API.
- Spark supports Python, Scala, Java & R
- ANSI SQL compatibility in Spark.
- Spark uses in-memory(RAM) for computation.
* 출처 : https://www.geeksforgeeks.org/difference-between-spark-dataframe-and-pandas-dataframe/