python - Extract a column from a DataFrame -
just basic question block me lot. how can extract column dataframe , have dataframe output ?
suppose have :
>>> dfm <class 'pandas.core.frame.dataframe'> datetimeindex: 17544 entries, 2015-01-01 00:00:00 2016-12-31 23:00:00 data columns (total 23 columns): t1 17544 non-null values t2 17544 non-null values >>> df = dfm['t1']
here df not dataframe. found subterfuge copy dataframe , del columns it's time consumming.
alexis
you can use [[]]
instead of []
:
df = dfm[['t1']]
for example:
from pandas import dataframe df = dataframe(dict(a=range(10), b=range(10))) type(df['b']) # <class 'pandas.core.series.series'> type(df[['b']]) # <class 'pandas.core.frame.dataframe'>
this works because passing list of 1 (['b']
) column subset operator.
Comments
Post a Comment