[ Web Proxy ]
URL:
Viewing:
https://raw.githubusercontent.com/We2one/Notes/master/python-basic-notes/python-days/Day_71.md
[Back]
[Original]
### Pandas #### ##### + + **** + 1. () series unique : , 1. (list) , 2. `DF_name.drop_duplicates(self, subset: Optional[Union[Hashable, Sequence[Hashable]]] = None, keep: Union[str, bool] = "first", inplace: bool = False, ignore_index: bool = False,)` + | | | | ---------------- | ------------------------------------------------------------ | | **subset** | None,, DF | | **keep** | **{first, last, False}**, first
**first**
**last**
**False** | | **inplace** | Falseinplace=TrueDataFrameFalse | | **ignore_index** | | 2. () -- () + **[-1, 1]** + **1** : + **0** : + **-1** : + `df.corr(self, method="pearson", min_periods=1)` + + **method** : *{"pearson", "kendall", "spearman"}* pearson , + ```python import pandas as pd df1 = pd.DataFrame([ [10, 20], [50, 100], [20, 40]], columns=["A", "B"] ) # method pearson , # {"pearson", "kendall", "spearman"} print(df1.corr(method="pearson")) """ A B A 1.0 1.0 B 1.0 1.0 """ df2 = pd.DataFrame([ [10, 0], [50, 100], [20, -20]], columns=["A", "B"] ) print(df2.corr(method="pearson")) """ A B A 1.000000 0.921551 B 0.921551 1.000000 """ ``` + ** () ** 1. 1. `DF_name.isnull()` , True, False ( sum() `.isnull().sum()` ) *** Series*** ```python import pandas as pd df2 = pd.DataFrame([ [10, ], [50, 100], [20, -20]], columns=["A", "B"] ) # print(df2.isnull()) """ A B 0 False True 1 False False 2 False False """ print(df2.isnull().sum()) """ A 0 B 1 1 dtype: int64 """ print(df2.notnull()) print(df2.notnull().sum()) """ A B 0 True False 1 True True 2 True True A 3 B 2 dtype: int64 """ ``` 2. `DF_name.notnull()` : True , False ** *Series*** 3. `DF_name.info()` : ** *DataFrame*** ```python import pandas as pd df2 = pd.DataFrame([ [10, ], [50, 100], [20, -20]], columns=["A", "B"] ) print(df2.info()) """ RangeIndex: 3 entries, 0 to 2 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 A 3 non-null int64 1 B 2 non-null float64 dtypes: float64(1), int64(1) memory usage: 176.0 bytes None """ ``` 2. 1. : `DF_name.dropna(self, axis=0, how="any", thresh=None, subset=None, inplace=False)` + | | | | ----------- | ------------------------------------------------------------ | | **axis** | **{0 or 'index', 1 or 'columns'}, default 0** **0** --> , **1** --> | | **how** | **{'any', 'all'}, default 'any'**
**any** -->
**all** --> | | **thresh** | **int, optional**(axis=0)(axis=1) | | **subset** | subset=[1,2] 1,2 | | **inplace** | False , True | + ```python import pandas as pd df2 = pd.DataFrame([ [10, ], [50, 100], [20, -20]], columns=["A", "B"] ) # df2.dropna(axis=0, how="any", inplace=True) print(df2) """ A B 1 50 100.0 2 20 -20.0 """ ``` 2. : `DF_name[""]/DF_name.fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None,)` + | | | | ----------- | ------------------------------------------------------------ | | **value** | **** method | | **method** | **{pad, ffill,backfill, bfill, None}, default None**
**pad/ffill******
**backfill/bfill*****\*\****
***\*None\**** | | **axis** | | | **inplace** | TrueFalse
**True**
**False** | | **limit** | limit | 3. : --- + ** interp1d ** : y=ax+b + **, lagrange ** : + ```python from scipy.interpolate import interp1d # # from scipy.interpolate import lagrange # import numpy as np import pandas as pd x_data = np.array([1, 2, 3, 4, 5, 6, 7]) y_data = np.array([3, 5, 7, 9, np.nan, np.nan, 15]) # 2x+1 y_data2 = np.array([2, 8, 18,32, np.nan, np.nan, 98]) # 2* x^2 df = pd.DataFrame(data={"A":x_data, "B":y_data}) print(df) # b_nona = df["B"].notnull() # print(b_nona) # new_df = df.dropna(how='any', axis=0) # axis=0 # # 1() linear = interp1d(new_df["A"], new_df["B"]) # print("", linear([5,6])) # # lagrange lar = lagrange(new_df["A"].values, new_df["B"].values) print("", lar([5,6]), type(lar([5,6]))) print('-'*50) # na_mask = df["B"].isnull() # new_x = df.loc[na_mask, "A"] # # print(new_x.values) # new_y = linear(new_x.values) # # df.loc[na_mask, "B"] = new_y # # print("\n", df) ``` + **** + + , **** + : + **** + , + **3 (sigma)** + ****, ** + + (-3,+3) 0.3% 3 + **** + ** QL-1.5IQR** ** QU+1.5IQR** + **QL** + **QU** + **IQR** QU QL + 25% + ```python import numpy as np import pandas as pd import matplotlib.pyplot as plt # (50 ) [-10, 120] # arr = np.random.uniform(-10, 120, size=50) arr = np.random.uniform(-10, 0, size=3) # 50 arr = np.hstack((arr, np.arange(200, 400, 4))) # print(arr) df = pd.DataFrame({"": arr}) # print(df) # # 1. def get_normal_score(val): low = 0 high = 100 return low
Web Proxy Viewer |
New URL
|
Original Page