panda, column access

Andrew Zyman formisc at gmail.com
Mon Feb 27 16:43:05 EST 2017


On Monday, February 27, 2017 at 4:27:23 PM UTC-5, Pavol Lisy wrote:
> On 2/27/17, Andrew Zyman <XXX at gmail.com> wrote:
<skip>
> I think you meant:
> colnames = ['hostname']

arh... Exactly. Now the rest is "unfolding".


<skip>
> What do you want is probably:
> >>> data[colnames[0]].tolist()

this is great and the rest of the code works.
but the output of "list_data = data.hostname.tolist()" is the comma separated strings, and "list_data = data[colnames[0]].get_values()" is space separated list. I suspect the answer to my "why" is in your statements below .

> or maybe if you don't want to remember colnames:
> >>> data[data.columns[0]].tolist()
> Be careful! Type of data[x] depend on what type is x.
> >>> type(data['hostname'])  # -> pandas.core.series.Series
> >>> type(data[['hostname']])  # -> pandas.core.frame.DataFrame

Thank you Pavol, very helpful.



More information about the Python-list mailing list