Plot all pandas dataframe columns separately

Pandas subplots=True will arange the axes in a single column. import numpy as np import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame(np.random.rand(7,20)) df.plot(subplots=True) plt.tight_layout() plt.show() Here, tight_layout isn’t applied, because the figure is too small to arange the axes nicely. One can use a bigger figure (figsize=(…)) though. In order to have … Read more

Plot pandas dates in matplotlib

If you use a list containing the column name(s) instead of a string, data.set_index will work The following should show the dates on x-axis: #! /usr/bin/env python import pandas as pd import matplotlib.pyplot as plt data = pd.read_fwf(‘myfile.log’,header=None,names=[‘time’,’amount’],widths=[27,5]) data.time = pd.to_datetime(data[‘time’], format=”%Y-%m-%d %H:%M:%S.%f”) data.set_index([‘time’],inplace=True) data.plot() #OR plt.plot(data.index, data.amount)

When is it appropriate to use df.value_counts() vs df.groupby(‘…’).count()?

There is difference value_counts return: The resulting object will be in descending order so that the first element is the most frequently-occurring element. but count not, it sort output by index (created by column in groupby(‘col’)). df.groupby(‘colA’).count() is for aggregate all columns of df by function count. So it count values excluding NaNs. So if … Read more