I've download a time series from Quandl using the get()
function from Quandl
python module and called UNES_HARD_COAL_BR
and it has shape (24,19)
, 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 ll
and applying the drop()
method in my DataFrame
object, the list contain the name of column that i don't use. The challenge here is do it without create a list.
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)
Related
How to select only specific columns from a DataFrame with MultiIndex columns?
pandas: Extracting specific selected columns from a DataFrame to new DataFrame