1. Extracting and transforming data - upalr/Python-camp GitHub Wiki

1 Indexing DataFrames

1.1 A simple Dataframe

1 a-simple-dataframe

1.2 Indexing using square brackets

2 indexing-using-square-bracket

1.3 Using column attribute and row label

3 using-column

1.4 Using the .loc accessor

4 loc

1.5 Using the .iloc accessor

5 iloc

1.6 Selecting only some columns

6 some-columns

2 Slicing DataFrames

Please watch this from the link as you are already familiar with this slicing stuffs.

Slicing Dataframes

2.1 Exaple: 1 : Slicing rows

Slice the row labels 'Potter' to 'Perry' in reverse order. To do this for hypothetical row labels 'a' and 'b', you could use a stepsize of -1 like so: df.loc['b':'a':-1].

3 Filtering dataframes

3.1 Creating a Boolean series

7 creating-a-boolean-series

3.2 Filtering with a Boolean Series

8 filtering-with-a-boolean-series

3.3 Combining filters

9 combining-filters

3.4 Dataframes with zeros and NaNs

10 dataframes-with-zeros-and-nans

3.5 Select columns with all non nonzeros

11 select-columns-with-nonzeroes

Excludes the baconcolumn because it has zero entries.

3.6 Select columns with any nonzeros

12 selecting-columns-with-anyy-nonzero

In this case, there is no columns with all zeroes so all off df2 is returned.

3.7 Select columns with any NaNs

13 selecting-columns-with-any-nans

Combining any() and isnull() returns any columns that have a NaN value.

3.8 Select columns without NaNs

We might want all columns where all column is present.

14 selecting-columns-without-nans

3.9 Drop rows with any NaNs

15 drop

3.10 Filtering a column based on another

16 filtering-a-column-based-on-another

3.11 Modifying a column based on another

17 modifing-a-column-based-on-another

3.12 Example 1 : Filtering using NaNs

Filtering using NaNs

4 Transforming DataFrames methods

4.1 Dataframe vectorized methods

18 dataframe-vectorized-method

4.2 NumPy vectorized functions

19 numpy-vectorized-sunction

4.3 Plain python functions (1)

20 plain-pythin-functions

4.4 Plain python functions (2)

21 plain-python -function-2

4.5 Storing a transformation

22 storing-a-tansformation

4.6 The dataframe index

23 the-dataframe-index

4.7 Working with string values (1)

24 working-with-string-values

4.8 Working with string values (2)

25 working-with-string-values-2

4.9 defining columns using other columns

26 defining0-columns-using-other-columns

4.10 Example 2: Using apply() to transform a column

Using apply() to transform a column

4.11 Example 3: Using .map() with a dictionary

Using .map() with a dictionary