M
M
Mark Adams2016-03-16 21:30:36
Python
Mark Adams, 2016-03-16 21:30:36

How to select desired data in Pandas?

I know that you can access data through column names:

import pandas

data = pandas.read_csv('name.csv', index_col='name')
data['name']

But how can I display several (desired) columns at once? Pull out only the data that is needed for work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Drozdov, 2016-03-17
@Ardarick

in a square bracket, you can specify conditions regarding values ​​for a specific column, for example:
data = pandas.read_csv('test.csv', delimiter=';')
print(data[data.a == 0])
or
print(data[data .a < 500])
where a is the name of the column.
there can be many conditions:
print(data[data.a < 500][data.b >= 100]) and so on.
Or you can select several columns separately, and then stitch them together.

D
Dmitry, 2016-03-17
@DemiKam

In [69]: from pandas import DataFrame, Series
In [70]: import pandas as pd
In [71]: frame = DataFrame(records) # records --> массив данных
In [72]: frame
Out[72]: 'структурированные данные' в виде таблицы

here is a sample of how pandas structures (download ipyt...
In [73]:  frame['tz'][:10] # <--- ну а после как тебе надо делаеш выборку ---!>
Out[73]: 
0     America/New_York
1       America/Denver
2     America/New_York
3    America/Sao_Paulo
4     America/New_York
5     America/New_York
6        Europe/Warsaw
7        
Name: tz, dtype: object

I took tabular data here (there are a lot of statistics, ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question