Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyspark dataframe to single csv

df.repartition(1).write.csv('/path/csvname.csv')
Comment

write PySpark dataframe to csv

# In this example, change the field column_as_array to column_as_string before saving.

from pyspark.sql.functions import udf
from pyspark.sql.types import StringType

def array_to_string(my_list):
    return '[' + ','.join([str(elem) for elem in my_list]) + ']'

array_to_string_udf = udf(array_to_string, StringType())

df = df.withColumn('column_as_str', array_to_string_udf(df["column_as_array"]))

# Then you can drop the old column (array type) before saving.
df.drop("column_as_array").write.csv(...)
Comment

PREVIOUS NEXT
Code Example
Python :: panda dataframe read csv change string to float 
Python :: or statement django template 
Python :: python pop up box 
Python :: python title case 
Python :: django queryset get all distinct 
Python :: telethon invite to group 
Python :: sort by dataframe 
Python :: make coordinate cyclic in python 
Python :: openpyxl delete column by name 
Python :: how to convert input to uppercase in python 
Python :: python image to video 
Python :: pandas dataframe column to datetime 
Python :: creata daframe python 
Python :: timed loop python 
Python :: run django server 
Python :: cprofile usage python 
Python :: delete the duplicates in python 
Python :: como deixar todas as letras maiusculas no python 
Python :: pyperclip 
Python :: read xls file in python 
Python :: convert number to binary in python 
Python :: import QMessageBox PyQt5 
Python :: python transform two columns to a list combine 
Python :: mount drive google colab 
Python :: adding a pandas column with multiple conditions 
Python :: package for downloading from youtybe for python 
Python :: discord get username slash command 
Python :: python version kali linux 
Python :: numpy create a matrix of certain value 
Python :: django widgets 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =