title: Writing in a csv file the dataset obtained in Python
body: <p>I have filtered a dataset in Python, from 4067642 items to 54 items. And now I need only to work with that subset in Excel, or R, since it was not possible working with the original dataset for the massive dimension. What I have to do is just exporting from Python environment my subdataset, writing it on csv file. </p>
  
  <p>I never used Python before, could you suggest me which line should I write to run this command? I'm going to copy the all code, that is not too long, it is quite short, since the activity that I had to do was only to filter the data.</p>
  
  <pre><code>&gt; import pandas as pd import numpy as np import csv import
  &gt; matplotlib.pyplot as plt
  &gt; 
  &gt; dir_file = "data/final_data/raw_data/" f_anac = dir_file +
  &gt; "anacDataset_1525953489668.csv"
  &gt; #df = pd.read_csv(f_anac, sep="\t", error_bad_lines=False, parse_dates=True) df = pd.read_csv(f_anac, sep="\t", parse_dates=True,
  &gt; dtype= {"cfStrutturaProponente": str})
  &gt; 
  &gt; #ci sono typo in alcune date (e.g. 202/02/2016) df['dataInizio'] = pd.to_datetime(df['dataInizio'], errors='coerce', format="%d/%m/%Y")
  &gt; df['dataUltimazione'] = pd.to_datetime(df['dataUltimazione'],
  &gt; errors='coerce', format="%d/%m/%Y")
  &gt; 
  &gt; #pulisco i dati dalla string CDATA ed elimino spazi da i cf degli aggiudicatari df.oggetto = df.oggetto.apply(lambda x
  &gt; :str(x).lower().replace('cdata', ''))
  &gt; df.denominazionePrimoaggiudicatario =
  &gt; df.denominazionePrimoaggiudicatario.apply(lambda x
  &gt; :str(x).lower().replace('cdata', '')) df.cfPrimoaggiudicatario =
  &gt; df.cfPrimoaggiudicatario.str.replace(' ', '')
  &gt; 
  &gt; df.info()
  &gt; 
  &gt; is_Lamezia = (df['denominazioneStrutturaProponente'] == 'COMUNE DI
  &gt; LAMEZIA TERME') df_Lamezia = df.loc[is_Lamezia] print('Dimensione
  &gt; dataset originario', df.shape) print('Dimensione dataset filtrato',
  &gt; df_Lamezia.shape)
  </code></pre>
  
  <p>This is the structure of the dataset:</p>
  
  <pre><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
  RangeIndex: 4067642 entries, 0 to 4067641
  Data columns (total 17 columns):
  cig                                  object
  cfStrutturaProponente                object
  denominazioneStrutturaProponente     object
  oggetto                              object
  sceltaContraente                     object
  importoAggiudicazione                float64
  importoSommeLiquidate                float64
  dataInizio                           datetime64[ns]
  dataUltimazione                      datetime64[ns]
  jsonPartecipanti                     object
  jsonAggiudicatari                    object
  totalePartecipanti                   int64
  totaleAggiudicatari                  int64
  totaleRaggruppamentopartecipanti     int64
  totaleRaggruppamentoAggiudicatari    int64
  cfPrimoaggiudicatario                object
  denominazionePrimoaggiudicatario     object
  dtypes: datetime64[ns](2), float64(2), int64(4), object(9)
  memory usage: 527.6+ MB
  </code></pre>
  
  <p>I have tried to use <code>writer=csv.writer(df_Lamezia,dialect="excel")</code>, but it doesn't work. This is why I have not at all a knowledge of how to export data in csv in Python.
  Could you help me?</p>