[PYTHON] mémorandum pandas

mémorandum pandas

Aperçu

«Ce n'est qu'un mémo, mais je vais le résumer facilement.

référence

Méthode

Lire le fichier csv

In [1]: df = read_csv('./input/hoge.csv')

Vérifiez le contenu

In [2]: df
Out[3]:
  label  a   b    c  d
0    aa  1  11  111  e
1    bb  2  22  222  e
2    cc  3  33  333  e
3    dd  4  44  444  e

Extraire la première étiquette

In [2]: df[[1]]
Out[2]:
   a
0  1
1  2
2  3
3  4

Extrait'a'label

In [3]: df['a']
Out[3]:
0    1
1    2
2    3
3    4
Name: a, dtype: int64

Accédez à l'élément en spécifiant l'emplacement Partie 1 (spécifié par l'étiquette)

In [4]: df.loc[:,['a','b']]
Out[4]:
   a   b
0  1  11
1  2  22
2  3  33
3  4  44

Accédez à l'élément en spécifiant l'emplacement Partie 2 (spécifié par colonne)

In [5]: df.iloc[:,[1,2]]
Out[5]:
   a   b
0  1  11
1  2  22
2  3  33
3  4  44

Statistiques numériques

In [6]: df.describe()
Out[6]:
              a          b           c
count  4.000000   4.000000    4.000000
mean   2.500000  27.500000  277.500000
std    1.290994  14.200939  143.300384
min    1.000000  11.000000  111.000000
25%    1.750000  19.250000  194.250000
50%    2.500000  27.500000  277.500000
75%    3.250000  35.750000  360.750000
max    4.000000  44.000000  444.000000

Au format numpy.ndarray

In [7]: df.values
Out[7]:
array([['aa', 1, 11, 111, 'e'],
       ['bb', 2, 22, 222, 'e'],
       ['cc', 3, 33, 333, 'e'],
       ['dd', 4, 44, 444, 'e']], dtype=object)

Obtenir le type de données pour chaque étiquette

>>> df.dtypes
target      int64
v1        float64
v2        float64
v3         object
v4        float64
v5        float64
v6        float64
v7        float64
v8          int64
v9        float64
dtype: object

Sélectionner par type de données d'étiquette

>>> df.ix[:, df.dtypes == np.int64]
         target     v8
   No.1      1      2
   No.2      2      2

iteritems(), iterrows()

>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c'])
>>> df
    A  	B   C
a	1	4    a
b	2	5    b
c	3	6    c

>>> for (key,column) in df.iteritems():
        print key
        print column
A
a    1
b    2
c    3
Name: A, dtype: int64
B
a    4
b    5
c    6
Name: B, dtype: int64
C
a    x
b    y
c    z
Name: C, dtype: object
>>> for (key, row) in df.iterrows():
        print key
        print row
a
A    1
B    4
C    x
Name: a, dtype: object
b
A    2
B    5
C    y
Name: b, dtype: object
c
A    3
B    6
C    z
Name: c, dtype: object

factorize

>>> pd.factorize(df['A'])
(array([0, 1, 2]), Int64Index([1, 2, 3], dtype='int64'))
>>> pd.factorize(df['B'])
(array([0, 1, 2]), Int64Index([4, 5, 6], dtype='int64'))
>>> pd.factorize(df['C'])
(array([0, 1, 2]), Index([u'x', u'y', u'z'], dtype='object'))
>>> df['C'], indexer = pd.factorize(df['C'])
>>> df
	A	B	C
a	1	4	0
b	2	5	1
c	3	6	2
>>> indexer
Index([u'x', u'y', u'z'], dtype='object')

Recommended Posts

Mémorandum de Pandas
mémorandum pandas
Mémorandum d'opération Pandas
[Pour enregistrement] Mémorandum Pandas
Pandas
Mémorandum (pseudo Vlookup par pandas)
Mémorandum @ Python OU Séminaire: Pandas
Mémorandum Matplotlib
Mémo Pandas
mémorandum Linux
mémorandum jinja2
Mémorandum de développement ~ pandas, prévisions, structure de données ~
Mémorandum Django
Mémorandum de commandement
Mémorandum Python 2
mémorandum complot
Mémorandum Slackbot (1)
mémorandum de multitraitement
Mémorandum MetaTrader5
Notes de pandas
Mémorandum ShellScript
mémorandum pip
Mémorandum Python
mémorandum python
mémorandum python
Mémorandum DjangoGirls
Mémorandum de commandement
mémo pandas
mémorandum python
Mémorandum Python
pandas SettingWithCopyWarning
mémo d'auto-apprentissage pandas
Mémorandum de base Python
Mémorandum de type RAID
Mes pandas (Python)
Mémorandum de Python Pathlib
Mémorandum de sed
Mémorandum Python (algorithme)
Excel-> pandas-> sqlite
Mémorandum Linux [liens]
Mémorandum d'apprentissage profond
[pandas] Conseils GroupBy
lecture de données pandas
À propos de décrire les pandas
liens relatifs aux pandas
Pandas de valeur manquante
9rep - Pandas MySQL
Mémorandum d'API Revit
Commande mémorandum conda
Mémorandum de commande setuptools
Mémorandum Python [liens]
Mémorandum de procès tslearn
Trier par pandas
Mémorandum de base de Django
Mémorandum sur la validation
mémo pandas python
série pandas partie 1
[Note] les pandas se désempilent