def get_input(type, nrows, ncols, dtype, order='C', out_dtype=False): rand_mat = (cp.random.rand(nrows, ncols) * 10) rand_mat = cp.array(rand_mat, dtype=dtype, order=order) if type == 'numpy': result = np.array(cp.asnumpy(rand_mat), order=order) if type == 'cupy': result = rand_mat if type == 'numba': result = nbcuda.as_cuda_array(rand_mat) if type == 'cudf': result = cudf.DataFrame(rand_mat) if type == 'pandas': result = pdDF(cp.asnumpy(rand_mat)) if type == 'cuml': result = CumlArray(data=rand_mat) if out_dtype: return result, np.array(cp.asnumpy(rand_mat).astype(out_dtype), order=order) else: return result, np.array(cp.asnumpy(rand_mat), order=order)
def makeDataFrame(self): dataGather = {'제목': [], '일시': [], '내용': [], '링크': []} for item in self.allItems: dataGather['제목'].append( BeautifulSoup(item.title.get_text(strip=True), 'lxml').get_text()) pubDate = item.pubdate.get_text(strip=True) pubDate = dt.strptime(pubDate, '%a, %d %b %Y %H:%M:%S %z') pubDate = dt.strftime(pubDate, '%Y-%m-%d %H:%M:%S') dataGather['일시'].append(pubDate) dataGather['내용'].append( BeautifulSoup(item.description.get_text(strip=True), 'lxml').get_text()) dataGather['링크'].append(item.originallink.get_text(strip=True)) self.resData = pdDF(dataGather) self.resData.index += 1 self.fileWrite()
def liked_songs_to_csv(self, *args): from pandas import DataFrame as pdDF columns = ['title', 'artist(s)'] keys = { "added_at": lambda it: it['added_at'], "album": lambda it: it['track']['album']['name'], "album_type": lambda it: it['track']['album']['album_type'], "release_date": lambda it: it['track']['album']['release_date'], "total_tracks": lambda it: it['track']['album']['total_tracks'], "disc_number": lambda it: it['track']['disc_number'], "duration_ms": lambda it: it['track']['duration_ms'], "explicit": lambda it: it['track']['explicit'], "popularity": lambda it: it['track']['popularity'], "track_number": lambda it: it['track']['track_number'], "id": lambda it: it['track']['id'], "is_local": lambda it: it['track']['is_local'] } for kw in args: if kw.lower() in keys: columns.append(kw) df = pdDF(columns=columns) off = 0 i = 0 while True: results = self.sp.current_user_saved_tracks(limit=50, offset=off) off += 50 for item in results['items']: row = [ item['track']['name'], item['track']['artists'][0]['name'] ] if len(columns) > 2: for kw in columns[2:]: row.append(keys[kw](item)) df.loc[i] = row i += 1 if results["next"] is None: break df.to_csv('MySpotipyLikedSongs.csv')