9951 explained code solutions for 126 technologies


python-pandasHow to draw data frame histogram (bars charts)


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

a = {'a': np.random.normal(0,1,100), 'b' : np.random.normal(1,2,100)}
df = pd.DataFrame.from_dict(a)

df.hist()
plt.show()ctrl + c
import pandas as pd

load Pandas module

import numpy as np

load Numpy module for Python

.random.normal(0,1,100)

generates 100 elements with 0 mean and 1 standard deviation

.DataFrame.from_dict

creates Pandas DataFrame object from given dict (a)

.hist()

plots DataFrame data as a bar chart

import matplotlib.pyplot as plt

loads Matplotlib module to use plotting capabilities

plt.show()

renders plotted data