본문 바로가기

python pandas4

pandas - Complete Usage of loc and iloc Data Import import pandas as pd from sklearn.datasets import load_boston # Load the Boston Housing Prices dataset boston = load_boston() boston_df = pd.DataFrame(boston.data, columns=boston.feature_names) boston_df['PRICE'] = boston.target A complete usage of loc The .loc[] function in Pandas is a powerful tool for data indexing and selection. With the Boston Housing Prices dataset, you can use .. 2023. 7. 30.
pandas - Subsetting Columns and Rows Data Import import pandas as pd from sklearn.datasets import load_boston # Load the Boston Housing Prices dataset boston = load_boston() boston_df = pd.DataFrame(boston.data, columns=boston.feature_names) boston_df['PRICE'] = boston.target Subsetting a single column using the column name as an attribute To subset a single column from the Boston Housing Prices dataset, you can use the DataFrame's.. 2023. 7. 30.
pandas - Sorting DataFrame Data Import import pandas as pd from sklearn.datasets import load_boston # Load the Boston Housing Prices dataset boston = load_boston() boston_df = pd.DataFrame(boston.data, columns=boston.feature_names) boston_df['PRICE'] = boston.target Sorting DataFrame Sorting can be done using .sort_values(). We need to sepcify the columns in a list and also specify if we want to sort in ascending or desce.. 2023. 7. 30.
pandas - Basic DataFrame Inspection Data Import import pandas as pd from sklearn.datasets import load_boston # Load the Boston Housing Prices dataset boston = load_boston() boston_df = pd.DataFrame(boston.data, columns=boston.feature_names) boston_df['PRICE'] = boston.target Inspect DataFrame First Few Rows of the DataFrame: This will show the first few rows of the DataFrame, which will include both the input features (columns fro.. 2023. 7. 30.