If you have it as string
query = "'x':df['region'], 'y':df['age'], 'z': df['smoker']"
then you could use eval()
to convert it
data = eval("{" + query + "}")
Maybe it is not safe but it is fast and easy.
import pandas as pd
df = pd.DataFrame({
'region': [1,2,3],
'age': [4,5,6],
'smoker': [7,8,9],
'other': ['A','B','C'],
})
query = "'x':df['region'], 'y':df['age'], 'z': df['smoker']"
data = eval("{" + query + "}")
print(data)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…