Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyspark dataframe to single csv

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

save dataframe to a csv local file pyspark

df.repartition(1).write.format('com.databricks.spark.csv').save("/path/to/file/myfile.csv",header = 'true')
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 :: How to check palindrom in python 
Python :: python extract string 
Python :: python string cut right 
Python :: check if queryset is empty django template 
Python :: destroy label tkinter 
Python :: range(len()) in python 
Python :: python for loop with step 
Python :: password guessing game python 
Python :: gurobi python example 
Python :: python convert string to int 
Python :: max of double array python 
Python :: how to swap two variables without using third variable and default python functionality 
Python :: envScriptsactivate.ps1 : File 
Python :: how to run a python script in background windows 
Python :: replace comma with dot in column pandas 
Python :: wikipedia python module 
Python :: sklearn regression 
Python :: remove first element from list 
Python :: How to Adjust Title Position in Python 
Python :: how to make python code faster 
Python :: python generator example 
Python :: python primes 
Python :: temp python web server 
Python :: How to Use Python Glob Module 
Python :: docker flask 
Python :: multiplication table python 
Python :: how to create a virtual environment in python 
Python :: Converting Dataframe from the multi-dimensional list with column name 
Python :: installing private python packages from requirements.txt 
Python :: python opencv load image 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =