ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

How to create a dataframe from a text file

Автор: BigDataElearning

Загружено: 2021-06-03

Просмотров: 2051

Описание: https://bigdataelearning.com/course/a...
https://bigdataelearning.com/courses
https://bigdataelearning.com
Creating a dataframe from a text file involves 4 steps.
1. First is to create a RDD from the text file
2. Second step is to create a case class
3. Third step is to convert the RDD to row RDD using case class
4. Final step is to create dataframe from the schema RDD using to-DF method.

1. Let’s look at the first step of creating RDD. As we already know, this is done using the text file method of sparkContext object. Let’s create a RDD from a text file. Here I am using spark.sparkContext.textFile API to load the data. I am specifying the path to the text file within double quotes and enclosing with round braces.

This creates a RDD called employeeRdd.

issuing a cat statement to view the contents of the employee.text file. Here we can see that the individual fields are separated by comma.

2. Now let’s do the second step of creating case class. Creating case class is easy.
All we should do is type

case class caseclassname & within braces fields names and their data types separated by comma.

3. Now, let’s do the third step of converting it to row RDD using the case class. For this, applying Map transformation to the employeeRDD, to split the individual elements of the RDD, by using split function and by using ‘comma’ as the delimiter. On top of that, applying another map transformation to convert as Row object, with the first field as integer and to trim the second field for each of the records. This creates a RDD called empRowRdd.

4. Finally, we can apply toDF method on the empRowRdd to create employee-Df dataframe. Now that we have created employeeDf successfully, let’s see how to save the contents of the dataframe to external text file.

This can be done using saveAsTextFile method. applying rdd.saveAsTextFile on the dataframe. passing the destination file path within double quotes enclosed by round braces.

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
How to create a dataframe from a text file

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

What is a Dataset: 3 specific features that Dataset provides

What is a Dataset: 3 specific features that Dataset provides

How to Read from a text .txt file in Python! Pulling in data and filtering and modifying the info!

How to Read from a text .txt file in Python! Pulling in data and filtering and modifying the info!

Scripting with Python - Modify a TXT file

Scripting with Python - Modify a TXT file

Трамп объявил о прекращении огня / Конец российского наступления?

Трамп объявил о прекращении огня / Конец российского наступления?

How to use Microsoft Access - Beginner Tutorial

How to use Microsoft Access - Beginner Tutorial

4. Write DataFrame into CSV file using PySpark

4. Write DataFrame into CSV file using PySpark

Итоги дня | Обыски у главы МВД | Взрыв в центре Москвы | Кремль про конфликт с Баку

Итоги дня | Обыски у главы МВД | Взрыв в центре Москвы | Кремль про конфликт с Баку

Бэкапы, файлы и прочее

Бэкапы, файлы и прочее

“Патриоты” не летят, а гражданство США — отбирают: Вашингтон начинает чистку /№971/ Юрий Швец

“Патриоты” не летят, а гражданство США — отбирают: Вашингтон начинает чистку /№971/ Юрий Швец

SHAZAM Top 50🏖️Лучшая Музыка 2025🏖️Зарубежные песни Хиты🏖️Популярные Песни Слушать Бесплатно #40

SHAZAM Top 50🏖️Лучшая Музыка 2025🏖️Зарубежные песни Хиты🏖️Популярные Песни Слушать Бесплатно #40

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]