We have developed convolutional sparse coding (CSC) to attenuate noise in seismic data. CSC gives a data-driven set of basis functions whose coefficients form a sparse distribution. The noise attenuation method by CSC can be divided into the training and denoising phases. Seismic data with a relatively high signal-to-noise ratio are chosen for training to get the learned basis functions. Then, we use all (or a subset) of the basis functions to attenuate the random or coherent noise in the seismic data. Numerical experiments on synthetic data show that CSC can learn a set of shifted invariant filters, which can reduce the redundancy of learned filters in the traditional sparse-coding denoising method. CSC achieves good denoising performance when training with the noisy data and better performance when training on a similar but noiseless data set. The numerical results from the field data test indicate that CSC can effectively suppress seismic noise in complex field data. By excluding filters with coherent noise features, our method can further attenuate coherent noise and separate ground roll.