<jupyter_start><jupyter_text>- Whenever a column has a name and value in it, even one missing values and that column stores numeric values, those values have to be stored as floating point numbers or decimal point<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba<jupyter_output><empty_output><jupyter_text>Shared Mwthods and Attributes between Series and DataFrame<jupyter_code>nba.head()
nba.index
nba.values # np array 
nba.shape # Give a tupple 
nba.dtypes
nba.dtypes.value_counts()<jupyter_output><empty_output><jupyter_text>DataFrame only Attributes<jupyter_code>nba.columns
nba.axes<jupyter_output><empty_output><jupyter_text>Method that exclusive to DataFrame<jupyter_code>nba.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 458 entries, 0 to 457
Data columns (total 9 columns):
 #   Column    Non-Null Count  Dtype  
---  ------    --------------  -----  
 0   Name      457 non-null    object 
 1   Team      457 non-null    object 
 2   Number    457 non-null    float64
 3   Position  457 non-null    object 
 4   Age       457 non-null    float64
 5   Height    457 non-null    object 
 6   Weight    457 non-null    float64
 7   College   373 non-null    object 
 8   Salary    446 non-null    float64
dtypes: float64(4), object(5)
memory usage: 32.3+ KB<jupyter_text>Difference between shared methods<jupyter_code>rev = pd.read_csv("pandas/revenue.csv", index_col = 'Date')
rev.head(3)
s = pd.Series([1, 2, 3])
s.sum()
rev.sum(axis = "index")
# Is the same as rev.sum()
rev.sum(axis =1) # Total of each row and it is the same as rev.sum(axis ="columns")<jupyter_output><empty_output><jupyter_text>Select one column from a DataFrame<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba.head(3)
nba.Name # Option1
nba.Number
nba.Salary

output = None 
nba['Name']<jupyter_output><empty_output><jupyter_text>Select Two or more columns from a DataFrame<jupyter_code>nba[['Name', 'Team']] # Order matters!
select = ["Salary", 'Team', 'Name']
nba[select]<jupyter_output><empty_output><jupyter_text>Add new column to DataFrame<jupyter_code>nba['Sport'] = "Basketball" # This will change the original dataFrame as well!
nba.head(3)
nba = pd.read_csv("pandas/nba.csv")
nba.insert(3, column = "Sport", value = "Basetball") # Will permanently replace original dataFrame
nba.head(3)<jupyter_output><empty_output><jupyter_text>Broadcasting Operations<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba.head(3)
nba['Age'].add(5)
nba['Age'] + 5
nba['Salary'].sub(5000000)
nba['Salary'] - 5000000
# Both of them are the same
nba['Weight'].mul(0.453592) # Multiply
nba['Weight'] * 0.453592
nba['Weight in Kilogram'] = nba['Weight'].mul(0.453592)
nba['Salary'].div(1000000)
nba['Salary']/1000000 # Pandas will deal with NaN as the same!<jupyter_output><empty_output><jupyter_text>A Review on the .value_counts() Method- value counts only exists in series<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba['Team'].value_counts().head(3)
nba['Position'].value_counts()<jupyter_output><empty_output><jupyter_text>Drop rows with Null values<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba.dropna()
nba.dropna(how = 'all', inplace = True) # IF all the values are null then it will be removed!
nba.tail(3)
nba.dropna(axis = 1) # Remove the column that has null value, not permanently!
# The same as nba.dropna(axis = 'Column')
nba.dropna(subset = ['Salary'])
nba.dropna(subset = ['Salary', 'College']) # Remove only Nulls in Salary and College!<jupyter_output><empty_output><jupyter_text>Fill in Null values with the .fillna() Method<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba.fillna(0) # Does not make sense in college column 
nba['Salary'].fillna(0, inplace = True)
nba.head()
nba['College'].fillna("No College", inplace = True)
nba.head()<jupyter_output><empty_output><jupyter_text>The .astype() method<jupyter_code>nba = pd.read_csv("pandas/nba.csv").dropna(how = 'all')
nba['Salary'].fillna(0, inplace = True)
nba['College'].fillna('No College', inplace = True)
nba.head(6)
nba.dtypes
nba.info()
nba['Salary'] = nba['Salary'].astype('int')
nba['Number'] = nba['Number'].astype('int')
nba['Age'] = nba['Age'].astype('int')
# Category only exist in Pandas not in Python
nba['Position'].nunique()
nba['Position'].unique()
nba['Position'] = nba['Position'].astype('category')
nba['Team'].nunique()
nba['Team'] = nba['Team'].astype('category')<jupyter_output><empty_output><jupyter_text>Sort a DataFrame with the sort_values Method,<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba.head(3)
nba.sort_values("Name", ascending = False) # Sort in DatafFrame need to be specified the column!
nba.sort_values("Salary", ascending = False, inplace = True)  # NaN will be placed very end in sort!
nba.head(3)
nba.sort_values('Salary').tail()
nba.sort_values('Salary',na_position = 'first')
nba.sort_values('Salary',ascending = False, na_position = 'first').tail()
nba.sort_values(['Team','Name'], ascending = [True, False], inplace = True)<jupyter_output><empty_output><jupyter_text>Sort DataFrame with .Sort_index() Method<jupyter_code>nba = pd.read_csv("pandas/nba.csv")
nba.head(3)
nba.sort_values(['Number','Salary', 'Name'], inplace = True)
nba.tail(3)
nba.sort_index() # Use this will back to original order
nba.sort_index(ascending = False, inplace = True)<jupyter_output><empty_output><jupyter_text>Rank values with the .rank() Method- In order to make this work, we will need to drop all null values first<jupyter_code>nba = pd.read_csv("pandas/nba.csv").dropna(how = "all")
nba['Salary'] = nba['Salary'].fillna(0).astype('int')
nba.head(6)
nba['Salary'].rank() # Rank in reverse order
nba['Salary_rank'] = nba['Salary'].rank(ascending = False).astype('int') # Will give higher salary lower rank!
nba.head()
nba.sort_values(by = 'Salary', ascending = False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15251329559101046, 'fraction_numerical': 0.022988505747126436, 'mean_word_length': 5.794871794871795, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '430466', 'license': 'Apache-2.0', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2165, 'n_words': 488, 'path': 'Section 4_DataFrames I__Introduction.ipynb', 'repo_name': 'YCTsai1997/Udemy_Data_Analysis_with_Pandas_and_Python', 'size': '5829'}