How to select specific columns from a DataFrame pandas object?
<p>I've download a time series from <a href="https://www.quandl.com/" rel="nofollow noreferrer">Quandl</a> using the <code>get()</code> function from <code>Quandl</code> python module and called <code>UNES_HARD_COAL_BR</code> and it has shape <code>(24,19)</code>, but i want use only the column 1 to 3 and the column 18. I wrote this script to do this job using a list called <code>ll</code> and applying the <code>drop()</code> method in my <code>DataFrame</code> object, the list contain the name of column that i don't use. <strong>The challenge here is do it without create a list.</strong></p>

<pre><code>import Quandl
import pandas as pd

UNES_HARD_COAL_BR = Quandl.get("UENG/CL_BRA", authtoken="xX6ntNSFuvq7eCZvDdvL")
UNES_HARD_COAL_BR.columns = UNES_HARD_COAL_BR.columns.str.replace(' ', '_')



ll =['Hard_coal_-_transformation_(Metric_tons,_thousand)', 'Hard_coal_-_transformation_in_coke_ovens_(Metric_tons,_thousand)','Hard_coal_-_transformation_in_electricity,_CHP_and_heat_plants_(Metric_tons,_thousand)','Hard_coal_-_transformation_in_electricity_plants_-_main_activity_producers_(Metric_tons,_thousand)','Hard_coal_-_final_energy_consumption_(Metric_tons,_thousand)','Hard_coal_-_consumption_by_manufacturing,_construction_and_non-fuel_mining_industry_(Metric_tons,_thousand)','Hard_coal_-_consumption_by_other_manuf.,_const._and_non-fuel_ind._(Metric_tons,_thousand)','Hard_coal_-_final_consumption_(Metric_tons,_thousand)','Hard_coal_-_stock_changes_(Metric_tons,_thousand)','Hard_coal_-_transformation_in_electricity_plants_-_autoproducers_(Metric_tons,_thousand)','Hard_coal_-_consumption_by_transport_(Metric_tons,_thousand)','Hard_coal_-_consumption_by_rail_(Metric_tons,_thousand)','Hrad_coal_-_consumption_by_iron_and_steel_industry_(Metric_tons,_thousand)', 'Hard_coal_-_losses_(Metric_tons,_thousand)', 'Hard_coal_-_total_energy_supply_(Metric_tons,_thousand)']

UNES_HARD_COAL_BR.drop(ll, axis=1, inplace=True)
</code></pre>

<h2>Related</h2>

<p><a href="https://stackoverflow.com/questions/18470323/how-to-select-only-specific-columns-from-a-dataframe-with-multiindex-columns">How to select only specific columns from a DataFrame with MultiIndex columns?</a></p>

<p><a href="https://stackoverflow.com/questions/34682828/pandas-extracting-specific-selected-columns-from-a-dataframe-to-new-dataframe">pandas: Extracting specific selected columns from a DataFrame to new DataFrame</a></p>