You can try getItem(0):

df \
    .withColumn("CurrencyCode", df["CurrencyCode"].getItem(0).cast("string")) \
    .withColumn("TicketAmount", df["TicketAmount"].getItem(0).cast("string")) 

The final cast to string is optional.

Answer from Daniel de Paula on Stack Overflow
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.to_string.html
pyspark.pandas.DataFrame.to_string — PySpark 4.1.2 documentation
DataFrame.to_string(buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=None, index_names=True, justify=None, max_rows=None, max_cols=None, show_dimensions=False, decimal='.', line_width=None)[source]#
🌐
Spark By {Examples}
sparkbyexamples.com › home › hbase › pyspark – convert array column to a string
PySpark - Convert array column to a String - Spark By {Examples}
July 22, 2020 - In this PySpark article, I will explain how to convert an array of String column on DataFrame to a String column (separated or concatenated with a comma,
🌐
Databricks Community
community.databricks.com › t5 › data-engineering › transform-a-dataframe-column-as-concatenated-string › td-p › 52719
transform a dataframe column as concatenated string
November 23, 2023 - schema = StructType([StructField('meterDateTime', StringType(), True), StructField('meterId', LongType(), True), StructField('meteringState', StringType(), True), StructField('value', DoubleType(), True), StructField('versionTimestamp', StringType(), True), StructField('file_name', StringType(), False), StructField('file_modification_time', TimestampType(), False)]) ... What is the most efficient way of running sentence-transformers on a Spark DataFrame column? in Machine Learning 09-03-2025 · Best practices : Silver Layer to Salesforce in Data Engineering 08-27-2025 · Autoloader to concatenate CSV files that updates regularly into a single parquet dataframe. in Data Engineering 06-24-2024 · Making transform on pyspark.sql.Column object outside DataFrame.withColumn method in Data Engineering 05-31-2024
🌐
Statology
statology.org › home › pyspark: how to convert column from date to string
PySpark: How to Convert Column from Date to String
November 7, 2023 - This particular example converts the dates in the date column to strings in a new column called date_string, using MM/dd/yyyy as the date format. The following example shows how to use this syntax in practice. Suppose we have the following PySpark DataFrame that contains information about sales ...
🌐
Statology
statology.org › home › how to convert integer to string in pyspark (with example)
How to Convert Integer to String in PySpark (With Example)
October 11, 2023 - We can use the dtypes function ... in the DataFrame: #check data type of each column df.dtypes [('team', 'string'), ('points', 'bigint'), ('points_string', 'string')] We can see that the points_string column has a data type of string. We have successfully created a string column from an integer column. The following tutorials explain how to perform other common tasks in PySpark: How to Convert String to ...
Find elsewhere
🌐
Apache Software Foundation
archive.apache.org › dist › spark › docs › 3.4.0 › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.to_string.html
pyspark.pandas.DataFrame.to_string — PySpark 3.4.0 documentation
Convert DataFrame to HTML. ... >>> df = ps.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6]}, columns=['col1', 'col2']) >>> print(df.to_string()) col1 col2 0 1 4 1 2 5 2 3 6 · >>> print(df.to_string(max_rows=2)) col1 col2 0 1 4 1 2 5 · pyspark.pandas.DataFrame.to_spark pyspark.pandas.DataFrame.to_dict
🌐
Arab Psychology
scales.arabpsychology.com › stats › how-to-convert-column-from-date-to-string-in-pyspark
How To Convert Column From Date To String In Pyspark ?
November 15, 2023 - In order to convert a column from date to string in pyspark, you can use the to_date() function. This function takes in the date column as an argument and returns the converted string value.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pyspark › pyspark – cast column type with examples
PySpark - Cast Column Type With Examples - Spark By {Examples}
August 15, 2020 - In PySpark, you can cast or change the DataFrame column data type using cast() function of Column class, in this article, I will be using withColumn(),
🌐
Medium
datamadness.medium.com › casting-data-types-in-pyspark-f95d1326449b
Casting Data Types in PySpark. How often have you read data into your… | by Kyle Gibson | Medium
March 14, 2023 - This is what the output of .dtypes looks like on our initial DataFrame: ... As you can see, it’s a list of tuples containing the column name and data type. For this method, we will create a dictionary to map the data types we want for specific columns. If a column isn’t in our dictionary, then we want it to keep its original data type: ... from pyspark.sql.functions import to_date, col data_type_map = { 'Date': 'date', 'Amount': 'double', 'IsDiscounted': 'boolean' } df = spark.read.load('/mnt/datalake/raw/food_data') df_updated_schema = df\ .withColumn('Date', to_date(col('Date'), 'M/d/yyyy').alias('Date').cast('date'))\ .select([col(column_schema[0]).cast(data_type_map.get(column_schema[0], column_schema[1])) for column_schema in df.dtypes])
🌐
Towards Data Science
towardsdatascience.com › home › latest › how to change the column type in pyspark dataframes
How To Change The Column Type in PySpark DataFrames | Towards Data Science
January 20, 2025 - df.printSchema() root |-- colA: long (nullable = true) |-- colB: string (nullable = true) |-- colC: string (nullable = true) |-- colD: string (nullable = true) In the following sections, we will showcase how to change the column type of columns colB, colC and colD to DateType, DoubleType and IntegerType respectively. The first option you have when it comes to converting data types is [pyspark.sql.Column.cast()](https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.Column.cast.html) function that converts the input column to the specified data type.
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.to_varchar.html
pyspark.sql.functions.to_varchar — PySpark 4.1.2 documentation
If col is a datetime, format shall ... it is converted to a string in one of the formats: ‘base64’: a base 64 string. ‘hex’: a string in the hexadecimal format. ‘utf-8’: the input binary is decoded to UTF-8 string. New in version 3.5.0. ... Input column or ...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-change-column-type-in-pyspark-dataframe
How to Change Column Type in PySpark Dataframe ? - GeeksforGeeks
July 18, 2021 - Here we will use select() function, this function is used to select the columns from the dataframe ... Example 1: Change a single column. Let us convert the `course_df3` from the above schema structure, back to the original schema.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › convert multiple columns to string in pandas dataframe
Convert Multiple Columns to String in Pandas DataFrame - Spark By {Examples}
December 5, 2024 - To convert multiple columns to strings in a Pandas DataFrame, you can use the astype() method and specify the columns you want to convert. In this