I have a histogram created from a pandas dataframe that I would like to plot a vertical dashed line representing the mean of the dataset. I have reviewed this thread, which is exactly the style I am looking for, however, I cannot figure out how to make it work with my code (below):
import pandas as pd
import matplotlib.pyplot as plt
#import csv file into pandas dataframe
df = pd.read_csv('/path/to/my/file')
#calculating mean
m = df.mean()
#print(m)
#plotting histogram
df.plot(kind='hist')
#plt.axvline(m, color = 'r', linestyle = 'dashed', linewidth = 2)
I end up receiving this error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Not sure what that means, any help would be appreciated.
EDIT: My datafile is a csv with one column, first row is a header (string) and all subsequent 107 rows are values ranging from app. 1.0E+11 to 4.0E+11
Fake data (Python 2.7)
import io
import numpy as np
a = np.linspace(1, 4, num = 20)
s = 'E11\n'.join(map(str, a))
s += 'E11'
#print(s)
df = pd.read_csv(io.BytesIO(s))