Вы находитесь на странице: 1из 3

Pandas

 pandas is a Python package


 providing fast, flexible, and expressive data structures
 designed to make working with “relational” or “labeled” data both easy
and intuitive.
 It aims to be the fundamental high-level building block for doing
practical, real world data analysis in Python.

Series

It is data structure in Python which has both list & Dictionary features

To convert list to series

Import pandas as pd

X=[1,2,3]

Y=pd.series(x)

Series object will have index & value ie two column

Index starts from 0 to n

String list data is converted to object

Numerical list is converted to numeric

In lists empty values are indicated by None

When numeric None values are converted to series, it is NaN

Convert dictionary to series

X={“cricket”:”australia”, “kabaddi”:”india”}

Y=x.series(x)

Index is keys of dictionary

To get only index


y.index

attributes of series --

 iloc & loc are attributes of series object

to get value using numeric index- y.iloc[3]

to get value using label index y.loc[‘cricket’]

 set_value to change value for a given key


 append to append two series

can have mixed type keys

keys need not be unique

we can apply numpy functions on series

%%timeit -n 100 to determine the time taken for 100 iterations

Data frames

It is a data structure in pandas

Can have multiple columns with col names & row names

Each series can be put as one col

Can access elements of DF using index of 1 or 2 values

Drop col/row df.drop(‘col/row label’)

To make copy of d f df1=df.copy()

Assign None to a col df[‘col’]

To drop rows with na values Df.dropna()

To count num of values df.count()

Shell commands

Can be executed by preceding with !


!cat filename

Вам также может понравиться