I have a json document shaped like this (note that this schema isn't under my control - I can't go get rid of the hyphen in the key):
{
"col1": "value1",
"dictionary-a": {
"col2": "value2"
}
}
I use session.read.json(...) to read this json in to a dataframe (named 'df') like this:
df = session.read.json('/path/to/json.json')
I want to do this:
df2 = df.withColumn("col2", df.dictionary-a.col2)
I get the error:
AttributeError: 'DataFrame' object has no attribute 'dictionary'
How can I reference columns with hyphens in their names in pyspark column expressions?