I'm saving value of a column from pyspark dataframe to a variable that dataframe contains only one column for ex:
variable=df.select(df['columnA']).collect()
print(variable)
output:
[Row(columnA='value')]
but I want variable to contain only "value" how to achieve this?
CodePudding user response:
Try below code:
import pandas as pd
df = pd.read_csv(file_name)
variable_name = df[column_name]
CodePudding user response:
# Retrieving data from the "columnA" column
for col in df.collect():
print(col["columnA"])
# first row - first column
print(df.collect()[0][0])