From a pandas dataframe, I want just the value and not the index.
JavaScript
x
2
1
state_dist = df[df['candidate'] == 'Don Young']['state_dist']
2
Returns:
JavaScript
1
3
1
9 AK-00
2
Name: state_dist, dtype: object
3
Adding .to_string()
JavaScript
1
2
1
state_dist = df[df['candidate'] == 'Don Young']['state_dist'].to_string()
2
Returns:
JavaScript
1
2
1
'9 AK-00'
2
I do not want to loop, how can I just get:
JavaScript
1
2
1
'AK-00'
2
Advertisement
Answer
Always check the docs for the method you are using:
JavaScript
1
2
1
state_dist = df[df['candidate'] == 'Don Young']['state_dist'].to_string(index=False)
2