פונקציות pandas נפוצות

פונקציות pandas נפוצות#

categoy

name

use

Creation

pd.DataFrame

create a new dataframe from numpy array/dictionary. Can provide row and column names

pd.Series

create a new Series object from numpy array/dictionary. Can provide names

pd.read_csv

read a dataframe from csv file

df.to_csv

write a dataframe to a csv file

Basic information

df.info

print a summary of the dataframe: column names, dtypes, number of existing (non Na) values, etc.

df.head

return the first rows of a dataframe

df.tail

return the last rows of a dataframe

df.sample

return the random rows from a dataframe

Data access

df.index

get row labels of dataframe

df.columns

get column labels of dataframe

df.loc

get dataframe subset by labels

df.iloc

get dataframe subset by position

Manipulation

df.drop

remove rows or columns by label name

df.apply

apply a function on all rows/columns of a dataframe

df.map

apply a function on all values in a dataframe

df.sort_values

sort table rows according to the values over a column, or table columns according to the values across a row

Fusion

pd.concat

concatanate dataframes along an axis

pd.merge

merge the columns of two dataframes based on

misc.

df.groupby

split dataframe rows according to the values of some column. should be followed by a summary operation which will result in a single dataframe again

Aggregation

df.max

return the largest value along an axis

df.min

return the smallest value along an axis

df.idxmax

return the index of the largest value along an axis

df.idxmin

return the index of the smallest value along an axis

df.mean

return the mean value along an axis

df.median

return the median value along an axis

df.sum

return the sum total along an axis

df.count

return the number of existing (not Na) values along an axis