목록전체 글 (462)
Note
How to extract the row and column number of a particular cell with given criterion? # Input df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv') # Solution # Get Manufacturer with highest price df.loc[df.Price == np.max(df.Price), ['Manufacturer', 'Model', 'Type']] # Get Row and Column number row, col = np.where(df.values == np.max(df.Price)) # Get the va..
How to find if a given array has any null values? # Input url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' iris_2d = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0,1,2,3]) np.isnan(iris_2d).any() # output False
How to get the nrows, ncolumns, datatype, summary stats of each column of a dataframe? Also get the array and list equivalent. df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv') # number of rows and columns print(df.shape) # output (93, 27) # datatypes print(df.dtypes) # output Manufacturer object Model object Type object Min.Price float64 Price float64..
How to find the correlation between two columns of a numpy array? # Input url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' iris = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0,1,2,3]) # 1 np.corrcoef(iris[:, 0], iris[:, 2])[0, 1] # 2 from scipy.stats.stats import pearsonr corr, p_value = pearsonr(iris[:, 0], iris[:, 2]) print(corr) # output 0.8717541..
How to import only specified columns from a csv file? df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv', usecols=['crim', 'medv']) print(df.head()) # output crim medv 0 0.00632 24.0 1 0.02731 21.6 2 0.02729 34.7 3 0.03237 33.4 4 0.06905 36.2