3

I have a dataframe like below:

+---+-----+-------------------+
|  x|    y|                  z|
+---+-----+-------------------+
|xyz|12223|A,123@B,456@C,98765|
|abc|12456|              A,123|
+---+-----+-------------------+

I save it as csv:

index.write.csv("D:\\spark\\tmp\\dd2")

two issues here:

  1. Would you like tell me how to save the column name x,y,z to the header of csv please?
  2. How can I save the output to a single file please?

1 Answer 1

4

Would you like tell me how to save the column name x,y,z to the header of csv please?

You have to use header option:

index.write.option("header", "true").write(path)

How can I save the output to a single file please?

Write single CSV file using spark-csv

Sign up to request clarification or add additional context in comments.

1 Comment

@Robin Where are you defining header name like x,y,z?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.