Machine learning Pandas Library

catalogue

πŸ’₯ Personal profile
πŸ’– About the author: ⭐ ️heart_6662, still studying (volume), welcome to exchange and correct~ 😜
πŸ“ Personal homepage heart blogπŸ”₯
πŸ“§ If there are mistakes in the knowledge points of the article, please correct the message πŸ“! Learn and make progress with you
πŸ“£ Series column: Machine Learning 🍁
πŸ’¬ Maxim: the curtain of life may open at any time. The key is whether you are willing to perform or choose to avoid πŸ”₯
🧑 If you feel the blogger's article is good, please πŸ‘ The third company supports the blogger πŸ’Œ oh
Β 

1, Pandas Library

2, Pandas library data structure Series, DataFrame

1.Series -- index, values

2.DataFrame -- index, columns, values

Uploading... Re upload cancel

Specify or modify index method

When creating:

After creation:

3, Series, DataFrame operation

1. Basic operation

2. Matrix operation and general function

3. The basic statistical method axis specifies the operation axis

4, Series, DataFrame index and slice

1.Series Index and slice Index / numeric Index / Boolean Index

2.DataFrame index and slicing

5, Series, DataFrame delete operation

1.Series delete operation pop/drop/del

2.DataFrame deletion pop/drop/del

6, Series, DataFrame merge operation

1.Series consolidation

2.DataFrame consolidation

7, Pandas library and other common functions or methods

1, Pandas Library

import numpy as np
import pandas as pd

2, Pandas library data structure Series, DataFrame

a = pd.Series([1, 2, 3, 4, 5])

data = np.array([[95, 96, 97], [80, 85, 86], [56, 65, 70]])
frame = pd.DataFrame(data)
frame

It's not hard to see the difference between series and DataFrame: DataFrame is more beautiful. Ha ha, it accepts matrix data

See:

The difference between data types in dataseries and dataframes_ jolingcome blog - CSDN blog_ Differences between series and dataframe

1.Series -- index, values

a = pd.Series([1, 2, 3, 4, 5], index = ['a', 'b', 'c', 'd', 'e'])
a

2.DataFrame -- index, columns, values

frame = pd.DataFrame(data, index=['xiaoming', 'xiaohong', 'xiaohei'],
                      columns=['yuwen', 'yingyu', 'shuxue'])
frame

Specify or modify index method

When creating:

index, columns specifies the index. There are already indexes that can be reordered by index

After creation:

reindex method to re-establish the index or specify the index sort

rename modify index

frame_.rename(index={"xiaohong":"damao","xiaoming":"ermao","xiaohei":"Nicolas Cage"},
              columns={"yingyu":"English", "yuwen":"Literature", "shuxue":"Maths"})


Series.index = []
DataFrame.columns = []

3, Series, DataFrame operation

1. Basic operation

Calculated by index position

data = {"English":[80,70,60], 
        "Literature":[70,70,85],
        "Maths":[80,90,50],
        "Music":["A","B","C"]}
df = pd.DataFrame(data,index = ["alpha", "beta","theta"])
df * 2

When DataFrame and Series are "added", they are matched according to the columns of DF

data1 = {"English":[80,70,60], 
        "Literature":[70,70,85],
        "Maths":[80,90,50],}
df1 = pd.DataFrame(data1,index = ["alpha", "beta","theta"])
add_ = {'Maths':10,'English':10,'Literature':20,'Gym':"A"}
add_ = pd.Series(add_)

df1 + add_

2. Matrix operation and general function

df.T

3. Basic statistical methods

View some of the data

df.describe()

4, Series, DataFrame index and slice

1.Series Index and slice Index / numeric Index / Boolean Index

add_ = {'Maths':10,'English':10,'Literature':20,'Gym':"A"}
add_ = pd.Series(add_)
add_['Maths']

2.DataFrame index and slicing

Index index 	 Column: DF ['math '] 	 Line: DF loc[‘alpha’]

Digital index 	 df.iloc[] 	 Special rows can be indexed directly with digital slices

Boolean index

5, Series, DataFrame delete operation

Del / drop.po1 delete operation

β‘  del method: delete in place

x = pd.Series([10,23,31,16],index=list("abcd"))
display(x)
 
# When an index is deleted, the corresponding value is deleted
del x["b"]
display(x)

β‘‘ drop method: only when inplace=True is specified can it be deleted locally

x = pd.Series([10,23,31,16],index=list("abcd"))
display(x)
 
y = x.drop("a")
display(y)
dispaly(x)
 
# When inplace=True is specified, it belongs to in place deletion
x.drop("a",inplace=True)
display(x)

Β 

2.DataFrame deletion pop/drop/del

Similar to the Series delete operation pop/drop/del, you can think about it

6, Series, DataFrame merge operation

Generally, we can check the parameters of the method we use

1.Series consolidation

pd.concat()	combine_first()

2.DataFrame consolidation

pd.concat()	combine_first()	

pd.merge()	join()

7, Pandas library and other common functions or methods

head()	info()	describe()	

sort_index()	sort_values()

is_unique	value_counts()

rank()

Detailed visible Connection (splicing) of Series and DataFrame in pandas_ Xiaodongxie's blog - CSDN blog_ pandas series stitching

Tags: Python Algorithm Machine Learning

Posted by Onle on Sun, 01 May 2022 19:28:33 +0300