Rescaling data

We’re going to begin the Machine Learning portion of Math 10. The main goal will be to make predictions using data, but we’ll start with a simpler topic, rescaling numerical data so that each numerical column has mean 0 and standard deviation 1.

Preparing the Spotify dataset

  • Import the Spotify dataset, specify na_values=" ", and drop the rows containing missing values.

  • We won’t use all of the columns. Define a pandas DataFrame df which contains only the following columns from the Spotify dataset.

othercols = ["Artist", "Song Name", "Week of Highest Charting"]
numcols = ["Danceability", "Energy", "Speechiness", "Acousticness", "Valence", "Duration (ms)"]
import pandas as pd
import altair as alt
df = pd.read_csv("../data/spotify_dataset.csv", na_values=" ").dropna()
othercols = ["Artist", "Song Name", "Week of Highest Charting"]
numcols = ["Danceability", "Energy", "Speechiness", "Acousticness", "Valence", "Duration (ms)"]
df[numcols]
Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 0.714 0.800 0.0504 0.12700 0.589 211560.0
1 0.591 0.764 0.0483 0.03830 0.478 141806.0
2 0.563 0.664 0.1540 0.33500 0.688 178147.0
3 0.808 0.897 0.0348 0.04690 0.591 231041.0
4 0.736 0.704 0.0615 0.02030 0.894 212000.0
... ... ... ... ... ... ...
1551 0.762 0.700 0.0694 0.00261 0.608 209320.0
1552 0.528 0.870 0.0851 0.24000 0.714 181930.0
1553 0.765 0.523 0.0300 0.18400 0.394 217307.0
1554 0.832 0.550 0.0587 0.24900 0.881 152784.0
1555 0.448 0.603 0.0640 0.43300 0.422 221307.0

1545 rows × 6 columns

It’s important to give a list of column names inside the square brackets. The following doesn’t work because what’s inside the square brackets is not a list.

df['Danceability',
 'Energy',
 'Speechiness',
 'Acousticness',
 'Valence',
 'Duration (ms)']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3360             try:
-> 3361                 return self._engine.get_loc(casted_key)
   3362             except KeyError as err:

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: ('Danceability', 'Energy', 'Speechiness', 'Acousticness', 'Valence', 'Duration (ms)')

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
/var/folders/8j/gshrlmtn7dg4qtztj4d4t_w40000gn/T/ipykernel_60487/2983493298.py in <module>
----> 1 df['Danceability',
      2  'Energy',
      3  'Speechiness',
      4  'Acousticness',
      5  'Valence',

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
   3456             if self.columns.nlevels > 1:
   3457                 return self._getitem_multilevel(key)
-> 3458             indexer = self.columns.get_loc(key)
   3459             if is_integer(indexer):
   3460                 indexer = [indexer]

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3361                 return self._engine.get_loc(casted_key)
   3362             except KeyError as err:
-> 3363                 raise KeyError(key) from err
   3364 
   3365         if is_scalar(key) and isna(key) and not self.hasnans:

KeyError: ('Danceability', 'Energy', 'Speechiness', 'Acousticness', 'Valence', 'Duration (ms)')

Adding an extra set of square brackets fixes the issue, because now what’s inside the outer square brackets is a list.

df[['Danceability',
 'Energy',
 'Speechiness',
 'Acousticness',
 'Valence',
 'Duration (ms)']]
Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 0.714 0.800 0.0504 0.12700 0.589 211560.0
1 0.591 0.764 0.0483 0.03830 0.478 141806.0
2 0.563 0.664 0.1540 0.33500 0.688 178147.0
3 0.808 0.897 0.0348 0.04690 0.591 231041.0
4 0.736 0.704 0.0615 0.02030 0.894 212000.0
... ... ... ... ... ... ...
1551 0.762 0.700 0.0694 0.00261 0.608 209320.0
1552 0.528 0.870 0.0851 0.24000 0.714 181930.0
1553 0.765 0.523 0.0300 0.18400 0.394 217307.0
1554 0.832 0.550 0.0587 0.24900 0.881 152784.0
1555 0.448 0.603 0.0640 0.43300 0.422 221307.0

1545 rows × 6 columns

We can combine two lists using +.

othercols+numcols
['Artist',
 'Song Name',
 'Week of Highest Charting',
 'Danceability',
 'Energy',
 'Speechiness',
 'Acousticness',
 'Valence',
 'Duration (ms)']
df[othercols+numcols]
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 Måneskin Beggin' 2021-07-23--2021-07-30 0.714 0.800 0.0504 0.12700 0.589 211560.0
1 The Kid LAROI STAY (with Justin Bieber) 2021-07-23--2021-07-30 0.591 0.764 0.0483 0.03830 0.478 141806.0
2 Olivia Rodrigo good 4 u 2021-06-25--2021-07-02 0.563 0.664 0.1540 0.33500 0.688 178147.0
3 Ed Sheeran Bad Habits 2021-07-02--2021-07-09 0.808 0.897 0.0348 0.04690 0.591 231041.0
4 Lil Nas X INDUSTRY BABY (feat. Jack Harlow) 2021-07-23--2021-07-30 0.736 0.704 0.0615 0.02030 0.894 212000.0
... ... ... ... ... ... ... ... ... ...
1551 Dua Lipa New Rules 2019-12-27--2020-01-03 0.762 0.700 0.0694 0.00261 0.608 209320.0
1552 Jorge & Mateus Cheirosa - Ao Vivo 2019-12-27--2020-01-03 0.528 0.870 0.0851 0.24000 0.714 181930.0
1553 Camila Cabello Havana (feat. Young Thug) 2019-12-27--2020-01-03 0.765 0.523 0.0300 0.18400 0.394 217307.0
1554 Dadá Boladão, Tati Zaqui, OIK Surtada - Remix Brega Funk 2019-12-27--2020-01-03 0.832 0.550 0.0587 0.24900 0.881 152784.0
1555 Taylor Swift Lover (Remix) [feat. Shawn Mendes] 2019-12-27--2020-01-03 0.448 0.603 0.0640 0.43300 0.422 221307.0

1545 rows × 9 columns

df = df[othercols+numcols].copy()

We now have the same number of rows but only 9 columns.

df.shape
(1545, 9)

Copying a DataFrame

  • Define a new DataFrame df1 to be df. (Do not use copy.)

  • Change the upper-leftmost entry in df1.

  • Look at df. What do you notice?

df1 = df

Subtle issue: df1 and df are the exact same DataFrame (not just two separate but identical DataFrames). If you change one, you also change the other.

df1 is df
True
df1.iloc[0,0] = "Christopher"
df1.head()
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 Christopher Beggin' 2021-07-23--2021-07-30 0.714 0.800 0.0504 0.1270 0.589 211560.0
1 The Kid LAROI STAY (with Justin Bieber) 2021-07-23--2021-07-30 0.591 0.764 0.0483 0.0383 0.478 141806.0
2 Olivia Rodrigo good 4 u 2021-06-25--2021-07-02 0.563 0.664 0.1540 0.3350 0.688 178147.0
3 Ed Sheeran Bad Habits 2021-07-02--2021-07-09 0.808 0.897 0.0348 0.0469 0.591 231041.0
4 Lil Nas X INDUSTRY BABY (feat. Jack Harlow) 2021-07-23--2021-07-30 0.736 0.704 0.0615 0.0203 0.894 212000.0

Notice how the top-left entry in df changed, even though we were using df1.

df.head()
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 Christopher Beggin' 2021-07-23--2021-07-30 0.714 0.800 0.0504 0.1270 0.589 211560.0
1 The Kid LAROI STAY (with Justin Bieber) 2021-07-23--2021-07-30 0.591 0.764 0.0483 0.0383 0.478 141806.0
2 Olivia Rodrigo good 4 u 2021-06-25--2021-07-02 0.563 0.664 0.1540 0.3350 0.688 178147.0
3 Ed Sheeran Bad Habits 2021-07-02--2021-07-09 0.808 0.897 0.0348 0.0469 0.591 231041.0
4 Lil Nas X INDUSTRY BABY (feat. Jack Harlow) 2021-07-23--2021-07-30 0.736 0.704 0.0615 0.0203 0.894 212000.0

This is not the same for something like an integer.

x = 10
y = x
y = y+3
y
13

In this case, x does not get changed along with y.

x
10

This is a subtle issue and don’t worry if you find it confusing. The most important thing is to watch for subtle errors when working with multiple DataFrames.

df1 = df.copy()
df1.iloc[0,0] = "Math 10 Math 10"
df1.head()
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 Math 10 Math 10 Beggin' 2021-07-23--2021-07-30 0.714 0.800 0.0504 0.1270 0.589 211560.0
1 The Kid LAROI STAY (with Justin Bieber) 2021-07-23--2021-07-30 0.591 0.764 0.0483 0.0383 0.478 141806.0
2 Olivia Rodrigo good 4 u 2021-06-25--2021-07-02 0.563 0.664 0.1540 0.3350 0.688 178147.0
3 Ed Sheeran Bad Habits 2021-07-02--2021-07-09 0.808 0.897 0.0348 0.0469 0.591 231041.0
4 Lil Nas X INDUSTRY BABY (feat. Jack Harlow) 2021-07-23--2021-07-30 0.736 0.704 0.0615 0.0203 0.894 212000.0

In this case, changing df1 does not change df, because we used .copy().

df.head()
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 Christopher Beggin' 2021-07-23--2021-07-30 0.714 0.800 0.0504 0.1270 0.589 211560.0
1 The Kid LAROI STAY (with Justin Bieber) 2021-07-23--2021-07-30 0.591 0.764 0.0483 0.0383 0.478 141806.0
2 Olivia Rodrigo good 4 u 2021-06-25--2021-07-02 0.563 0.664 0.1540 0.3350 0.688 178147.0
3 Ed Sheeran Bad Habits 2021-07-02--2021-07-09 0.808 0.897 0.0348 0.0469 0.591 231041.0
4 Lil Nas X INDUSTRY BABY (feat. Jack Harlow) 2021-07-23--2021-07-30 0.736 0.704 0.0615 0.0203 0.894 212000.0

Let’s get back to our original DataFrame.

df.iloc[0,0] = "Måneskin"

Rescaling 1: using a for loop

  • Make a copy of df called df1.

  • Using a for loop, for each column in numcols, rescale df1 so that column has mean 0.

  • Check your answer using mean with the axis keyword argument.

We could also skip the axis=0 part, but it’s good to include it to remember that axis=0 means to compute the mean of each column, one at a time.

df[numcols].mean(axis=0)
Danceability          0.689997
Energy                0.633495
Speechiness           0.123656
Acousticness          0.248695
Valence               0.514704
Duration (ms)    197940.816828
dtype: float64
c = "Energy"
df[c].mean()
0.633495145631068

Here we are rescaling each of the numeric columns.

for c in numcols:
    df1[c] = df1[c] - df1[c].mean()

Notice that these numbers in the following output are very close to zero. This is probably as close as we can get, due to numerical precision issues.

df1[numcols].mean(axis=0)
Danceability    -8.738066e-17
Energy          -5.058880e-17
Speechiness      1.149746e-18
Acousticness     3.219287e-17
Valence          1.034771e-17
Duration (ms)   -6.630776e-12
dtype: float64

Here were the average values from the original DataFrame.

df[numcols].mean(axis=0)
Danceability          0.689997
Energy                0.633495
Speechiness           0.123656
Acousticness          0.248695
Valence               0.514704
Duration (ms)    197940.816828
dtype: float64

Rescaling 2: using apply

  • Make a copy of df called df2.

  • Using the apply method, rescale each column in numcols so it has mean 0. Specify the axis keyword argument so that apply operates on each column, one at a time.

df2 = df.copy()
df2.shape
(1545, 9)

Here is an example of applying the len function to each column. All of these columns have length 1545. Specifying axis=0 indicates that we are plugging in the columns, one at a time, not plugging in the rows.

df2.apply(len, axis=0)
Artist                      1545
Song Name                   1545
Week of Highest Charting    1545
Danceability                1545
Energy                      1545
Speechiness                 1545
Acousticness                1545
Valence                     1545
Duration (ms)               1545
dtype: int64

Here is an example of getting the 0-th entry from each column.

df2.apply(lambda s: s.iloc[0], axis=0)
Artist                                    Måneskin
Song Name                                  Beggin'
Week of Highest Charting    2021-07-23--2021-07-30
Danceability                                 0.714
Energy                                         0.8
Speechiness                                 0.0504
Acousticness                                 0.127
Valence                                      0.589
Duration (ms)                             211560.0
dtype: object

What we actually care about is subtracting the mean. Here is an example.

s = df["Energy"]
s-s.mean()
0       0.166505
1       0.130505
2       0.030505
3       0.263505
4       0.070505
          ...   
1551    0.066505
1552    0.236505
1553   -0.110495
1554   -0.083495
1555   -0.030495
Name: Energy, Length: 1545, dtype: float64

Now we can use that formula for each column. But notice that it only makes sense for numeric columns.

df2.apply(lambda s: s-s.mean(), axis=0)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in _ensure_numeric(x)
   1602         try:
-> 1603             x = float(x)
   1604         except (TypeError, ValueError):

ValueError: could not convert string to float: "MåneskinThe Kid LAROIOlivia RodrigoEd SheeranLil Nas XLil Nas XDoja CatRauw AlejandroBad BunnyMåneskinDua LipaJ Balvin, Maria BecerraBTSJustin BieberBTSOlivia RodrigoOlivia RodrigoThe WeekndNio Garcia, J Balvin, Bad BunnyDoja CatMora, Bad Bunny, SechDoja CatOlivia RodrigoGlass AnimalsThe WeekndOlivia RodrigoFarrukoPost MaloneRiton, NightcrawlersMasked WolfBruno Mars, Anderson .Paak, Silk SonicCamila CabelloOlivia RodrigoSebastian Yatra, Myke TowersHarry StylesPolo GDoja Cat, The WeekndSech, Jhay CortezBad Bunny, Jhay CortezTINI, Maria BecerraOlivia RodrigoJ Balvin, KAROL G, Nicky Jam, Crissin, Totoy El Frio, Natan & ShanderBTSTiëstoGalantis24kGoldnTiago PZK, LIT killahWisin, Jhay Cortez, Anuel AA, Los Legendarios, Myke TowersBella PoarchBizarrap, Nicky JamMarc Seguí, Rauw Alejandro, Pol GranchBillie EilishMajestic, Boney M.MarshmelloSurf CurseJoão GomesRauw Alejandro, Mr. NaisgaiMaroon 5OneRepublicMegan Thee StallionATB, Topic, A7SOlivia RodrigoThe WeekndGiveonDua LipaTrinidad CardonaThe NeighbourhoodMalumaLewis CapaldiSmileySleepy HallowKAROL G, Mariah AngeliqJustin Quiles, Chimbala, Zion & LennoxShouseMåneskinKali UchisGera MX, Christian NodalLos Legendarios, Wisin, Jhay CortezTones And IThe Kid LAROIDrakeBo BurnhamDua LipaTravis Scott, HVMEJoel CorryJoel Corry, RAYE, David GuettaJustin Wellington, Small JamBelly, The Weeknd, Young ThugDuncan LaurenceMora, Jhay CortezAriana GrandePost MaloneRAF Camora, Bonez MCNatti Natasha, Becky GJ Balvin, SkrillexDoja CatWILLOWDaveLewis CapaldiDua LipaMadison BeerBANDIDOImagine DragonsInternet MoneyBruno MarsSAINt JHNSechBecky G, El AlfaIngrataxBillie EilishPost Malone, Swae LeedhruvDoja CatCalvin HarrisLuan SantanaEd SheeranShawn Mendes, Camila CabelloJustin BieberEd SheeranMYA, TINI, DukiBad Bunny, ROSALÍADaBabyConan GrayTate McRaeAviciiVance JoyNirvanaOlivia RodrigoThe NeighbourhoodJoão GomesTrippie ReddMaroon 5Tom OdellJamie MillerHozierTom GrennanGusttavo LimaCardi BMalumaKhalidQueenMyke Towers, JuhnMEDUZATravis ScottOfenbachCamilo, Shawn MendesLady Gaga, Bradley CooperCochise, $NOTMari FernandezOneRepublicColdplayEmilia, DukiJoão Gomes, Vitor FernandesAviciiMatheus Fernandes, DilsinhoVegedreamPop SmokeAURORADaBabyDaBabyJuice WRLDLil Tjay, 6LACKBillie EilishP!nk, Willow Sage HartPop SmokeOlivia RodrigoCardi BThe KillersThe PoliceFleetwood MacJames ArthurNormaniPop SmokePop SmokePowfu, beabadoobeeAnne-Marie, Niall HoranQueenDrake, WizKid, KylaHarry StylesSarah CothranWalker HayesRauw AlejandroJohn LegendPolo GPop SmokeSaweetieThe WeekndSZAAnne-Marie, Little MixBad BunnyAriana GrandeBlxst, TygaMC Zaquin, MC RickTopic, A7SLuísa SonzaRoddy RicchDaveEminemPop SmokePop SmokeTrippie Redd, Lil Uzi VertPop SmokePop SmokeKSIPop SmokePop SmokeTyler, The CreatorPashanimTion Wayne, Russ MillionsPop SmokeNio Garcia, Flow La MovieBLANCO, Sfera EbbastaRegardBillie EilishJohn MayerImagine DragonsMc Davi, Mc Pedrinho, Mc Don JuanInternet MoneyImagine DragonsDua LipaBTSSechSelena GomezBasOlivia RodrigoIsrael & Rodolffo, Wesley SafadãoTWICEBIAKane Brown, blackbearAlex Rose, Rauw AlejandroDj Guuga, DJ IvisMaluma, Beéle, Rauw Alejandro, Mambo Kingz, DJ Luian, DarellRauw AlejandroThe Chainsmokers, HalseyOasisBrent FaiyazDoja CatBig Red MachineTyler, The CreatorBo BurnhamDJ KhaledStarBoi3LordeBillie EilishShirin DavidCJIsrael & RodolffoMiley CyrusGym Class HeroesRauw Alejandro, Anuel AAsangiovanniBizarrap, Eladio CarrionArctic MonkeysTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorDoja CatTyler, The CreatorTyler, The CreatorDoja CatMigosDoja CatDoja CatFedez, Achille LauroJ Balvin, Dua Lipa, Bad BunnyJawsh 685, Jason DeruloCrissin, Totoy El Frio, Natan & ShanderBozaTate McRae, KhalidSoso ManessJ. ColeJ. ColeXXXTENTACIONPolo GRoddy RicchNathan EvansMacklemore & Ryan LewisJustin BieberMachine Gun KellyBruno MarsTravis ScottDua LipaDrakeMartin GarrixRochy RD, Myke Towers, Nicki NicoleLinkin ParkJ. ColeTravis ScottThe Chainsmokers, ColdplayRegard, Troye Sivan, Tate McRaeMigosPolo GPolo GMaroon 5MigosAva MaxMigosBlack Eyed Peas, ShakiraPolo GMigosBillie EilishBad BunnyMC Kevin o ChrisColdplayLil Nas XPolo GLady GagaLil Baby, Lil DurkJohn MayerLil Baby, Lil DurkTOMORROW X TOGETHER, SeoriJ. ColeLil TeccaYoung Stoner Life, Young Thug, GunnaManuel Turizo, Rauw Alejandro, Myke TowersHarry StylesMåneskinKAROL GAshnikkoEminemAlok, Mc Don Juan, Dj GBRJuice WRLDJuice WRLDBTSMalu, DJ Lucas BeatEminemLil MoseyGotye, KimbraJustin BieberMc Poze do Rodo, Neo Beats, MainstreetJ. ColeBTSBTSBarbara PraviTwenty One PilotsTwenty One PilotsJ. ColeNicki MinajBlind ChannelGo_AITZYJ. ColeDrakeJoyner Lucas, Lil BabyBeach BunnyGjon's TearsLil TjayDreamDaði FreyrTwenty One PilotsJ. ColeJ. ColeJ. ColeJ. ColeJ. ColeJ. ColeThe Kid LAROIBizarrap, Snow Tha ProductNio Garcia, Casper Magico, Ozuna, Wisin & Yandel, Myke Towers, Flow La MovieMARINAHarry StylesMyke TowersMilly, Farruko, Nio Garcia, Jay Wheeler, AmenazzyDaddy YankeeJustin BieberGym Class HeroesJP SaxeDJ KhaledRuss Millions, Tion WayneBillie EilishDon ToliverBizarrap, L-GanteLil Nas XPink Sweat$Future187 Strassenbande, Bonez MC, FrauenarztJuice WRLDNicky Jam, Romeo SantosRaí Saia RodadaCamilo, Evaluna MontanerJuice WRLDJuice WRLDJorge & MateusElyOttoBaby KeemMachine Gun KellyDJ KhaledDJ KhaledAnittaROSÉTaylor SwiftBillie EilishJ Balvin, KhalidDemi LovatoPooh ShiestyLil TjayWisin, Myke Towers, Los LegendariosJustin BieberH.E.R.HVMERitt MomneyDiego & Victor Hugo, Bruno & MarroneJames ArthurShawn MendesThe WeekndXXXTENTACIONMimi WebbblackbearBruno MarsKAROL G, Anuel AA, J BalvinTwenty One PilotsYoung Stoner Life, Young Thug, GunnaYoung Stoner Life, Young Thug, GunnaTaylor SwiftWesley Safadão, Os Barões Da PisadinhaOs Barões Da PisadinhaTaylor SwiftArctic MonkeysEd SheeranJ Balvin, Bad BunnyTaylor SwiftTaylor SwiftDMXTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftDMXTaylor SwiftTaylor SwiftTaylor SwiftSebastian Yatra, GuaynaaSech, Daddy Yankee, J Balvin, ROSALÍA, FarrukoTaylor SwiftTaylor SwiftKHEA, DukiDemi LovatoROSÉSam Fischer, Demi LovatoPop SmokeKevin Roldan, Bryant Myers, LyannoJason DeruloJustin BieberAriana GrandeMother MotherDJ IvisRusherking, KHEA, Duki, Maria Becerra, LIT killah, Tiago PZKMaroon 5, Wiz KhalifaJustin BieberJustin BieberJack Harlowa-haCamilo, El AlfaJ BalvinJustin BieberJustin BieberKAROL G, Nicki MinajOzuna, J Balvin, Chencho CorleoneJustin BieberZoe WeesDrakeDJ Ivis, Tarcísio do AcordeonJason Derulo, NukaJustin BieberThe Weeknd, Daft PunkFarrukoHugo & GuilhermeJustin BieberJustin BieberLana Del ReyNicky Jam, Myke TowersLana Del ReyMaluma, Lenny TavárezCamiloCamiloHippie SabotageJustin QuilesSelena GomezKSIDJ SnakeSiaMachine Gun KellyJay Wheeler, DJ Nelson, Myke TowersRobin SchulzDoja CatXXXTENTACIONTame ImpalaThe Weeknd, Daft PunkPop SmokeBANNERSPamungkasBLACKPINKNF, HopsinMadamePop SmokeJuice WRLDFrancesca Michielin, FedezAnuel AA, OzunaBooba, JSXLil BabyLele PonsOfenbach, QuarterheadLil PeepBØRNSConan GrayPost MaloneAriana GrandeC. Tangana, Niño de Elche, La HúngaraThe Kid LAROIJustin QuilesArizona ZervasPost MaloneC. Tangana, Ed MaverickHalseyBad BunnyJustin BieberClairoEd SheeranBausa, Apache 207NFShawn MendesSabrina CarpenterJack HarlowSara KaysJason Derulo, Maroon 5Tones And IOzuna, CamiloAriana GrandeEd SheeranKAROL GBizarrap, Nathy PelusoMaluma, The WeekndRauw AlejandroTarcísio do AcordeonXXXTENTACIONEd SheeranDrakeThe WeekndSurf MesaOasisXXXTENTACIONJuice WRLDBillie EilishSia, David GuettaThe Weekndbenny blancoThe WeekndMiley CyrusMartin GarrixBring Me The HorizonMalumaKawe, Mc Lele JPThe WeekndAriana GrandeDean LewisMegan Thee StallionJerry DiKASIMIR1441, badmómzjay, WILDBWOYSBrent Faiyaz, DJ DahiZAYNOlivia RodrigoAshnikkoMorgan WallenNio Garcia, Anuel AA, Myke Towers, Brray, JuankaAnuel AA, OzunaMigrantes, AlicoMorgan WallenSelena GomezJack HarlowSam Smith347aidanRauw Alejandro, J BalvinTaylor SwiftChris Brown, Young ThugJuice WRLD, The Kid LAROIAnne-Marie, KSI, Digital Farm AnimalsLuísa Sonza, Pabllo Vittar, AnittaErica BanksAva MaxBLACKPINKOzunaFousheéMorgan WallenMorgan WallenMorgan WallenBad BunnySech, J BalvinPop SmokeMorgan WallenMorgan WallenOs Barões Da PisadinhaBLACKPINKMarshmelloDua Lipa, AngèleApache 207Taylor SwiftSurfacesPetter Ferraz, Menor NicoMarshmello, BastilleQueenJ BalvinOs Barões Da Pisadinha, Xand AviãoKid CudiMEDUZA, Becky Hill, GoodboysTWICECORPSE, Savage Ga$pMariah CareyWham!Ariana GrandeBrenda LeeBobby HelmsMichael BubléAndy WilliamsKelly ClarksonJosé FelicianoDean MartinFrank SinatraJustin BieberThe RonettesBand AidPaul McCartneyMichael BubléJohn Lennon, Yoko OnoNat King ColeBing Crosby, Ken Darby Singers, John Scott Trotter & His OrchestraPlayboi CartiBurl IvesThe PoguesShakin' StevensElvis PresleyChuck BerryThe Jackson 5Kylie MinoguePerry Como, The Fontane SistersDarlene LoveElton JohnKid CudiJonas EsticadoJorge & MateusDaryl Hall & John OatesColdplaySam SmithSiaBritney SpearsBrett EldredgeJonas BrothersAva MaxGwen StefaniEminemNat King ColeMichael BubléIdina MenzelTaylor SwiftThe Jackson 5Eartha Kitt, Henri Rene & His OrchestraMykola Dmytrovych Leontovych, John WilliamsTaylor SwiftStevie WonderShawn MendesDean MartinBruce SpringsteenLeona LewisThe Beach BoysLiam PayneMeghan TrainorDean MartinFrank SinatraFrank SinatraMariah CareyBing CrosbyPentatonixDonny HathawayTony BennettTaylor SwiftKaty Perry*NSYNCTaylor SwiftEaglesMeghan TrainorTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftKid CudiKid CudiKid CudiKid CudiKid CudiKid CudiKid CudiBad BunnyKid CudiKid CudiTaylor SwiftJuice WRLDShawn MendesThe WeekndTory Lanez, Jack HarlowBad BunnyLil BabyMiley CyrusBTSsalem ileseBad Bunny, Jowell & Randy, Ñengo FlowBad BunnyThe Kid LAROIStudio Killers24kGoldnBad BunnyBad BunnyBad BunnyBad BunnyBad Bunny, ABRABad BunnyBad BunnyPaul McCartneyBTSBTSBTSBTSMiley CyrusTrio VegabajeñoMiley CyrusJhay Cortez, Bad BunnyBTSSfera EbbastaClean Bandit, MabelChristian Nodal, Ángela AguilarSfera EbbastaMaster KGSfera EbbastaAya NakamuraThe Kid LAROIJuice WRLDBLACKPINKJawsh 685, Jason DeruloJustin TimberlakeSfera Ebbasta21 Savage, Metro BoominWallowsDan + ShayVedoManuel TurizoStaySolidRockyFuture, Lil Uzi VertKane BrownK/DA, Madison Beer, (G)I-DLE, Lexie Liu, Jaira Burns, Seraphine, League of LegendsRauw AlejandroFuture, Lil Uzi VertOctavian, SkeptaAriana GrandeTy Dolla $ignLittle MixMAXFuture, Lil Uzi VertNelly Furtado, TimbalandDJ KhaledAriana GrandeLabrinthAnuel AA, Bad BunnyKinaDDGLuke CombsJojiDaddy Yankee, Anuel AA, Kendo KaponiBillie EilishCali Y El Dandee, Danna PaolaAriana GrandeAriana GrandeAriana GrandeThe Kid LAROIKHEAMalumaOzuna, KAROL G, Myke Towers21 Savage, Metro BoominPop SmokeAriana GrandeAriana GrandeEd SheeranCamiloDon ToliverJ BalvinAriana GrandeAriana GrandeAriana GrandeMichael JacksonSam SmithBonez MCSam SmithAC/DCAnittaMoney ManSechTravis ScottBLACKPINKBig SeanAriana GrandeBlack Eyed Peas, Ozuna, J. Rey SoulLauv, Conan GrayMarshmello, Demi LovatoTHE SCOTTS, Travis Scott, Kid CudiTrueno, Bizarrap, Taiu, TATOOLPassengerMelanie MartinezKygo, OneRepublicAdeleAli GatieCurtis WatersBLACKPINKG-Eazy13 Organisé, SCH, Kofs, Jul, Naps, Soso Maness, Elams, Solda, HouariBLACKPINKBebe RexhaROSALÍACamiloBad BunnyLana Del ReyGunnaRauw Alejandro, Dalex, Lenny TavárezNoah CyrusLewis CapaldiBLACKPINKBENEE, Gus Dapperton21 Savage, Metro BoominZAYNMachine Gun KellyNiackFeid, J Balvin, Justin QuilesChris Brown21 Savage, Metro Boomin21 Savage, Metro Boomin21 Savage, Metro BoominBryson Tiller21 Savage, Metro Boomin21 Savage, Metro Boomin21 Savage, Metro BoominInternet MoneyJoji21 Savage, Metro BoominWhoHeem21 Savage, Metro Boomin21 Savage, Metro BoominJojiJojiJoji, DiploPolo GMachine Gun KellyJojiJojiJojiBea MillerSaweetieJojiJoji, BENEECalvin HarrisJuice WRLD, Polo GMachine Gun KellyHarry NachJack HarlowKendrick Lamar, Jay RockInternet Money, DiploEarth, Wind & FireRegard, RAYEPolo GDamso, HamzaDamsoTaylor SwiftJuice WRLDJuice WRLDLil TeccaDrake6ix9ineDua LipaKygo, Donna SummerAva MaxAva MaxOzuna, Doja Cat, SiaSZA, The Neptunes, Pharrell Williams, Ty Dolla $ignMaroon 5MatuêBonez MCAlex Rose, Rafa PabönLil BabyBonez MC, MaxwellMiley CyrusDoja CatHeadie OneNeaBeyoncé, Megan Thee StallionBig SeanSaweetieITZYTravis ScottMalumaRobin Schulz, WesK/DA, (G)I-DLE, Wolftyla, Bea Miller, League of LegendsMc Zaac, Anitta, TygaPeach Tree RascalsTaylor SwiftBlack Eyed Peas, J BalvinKitschKrieg, Jamule, SFRKygo, Tina TurnerKaty PerryConkarahCordaeJACKBOYS, Travis ScottJowell & Randy, J BalvinAnuel AALady GagaRod WaveJuice WRLDJustin Quiles, Daddy Yankee, El AlfaInternet Money, Gunna, Don Toliver, NAVCapital Bra, CroBTSSam SmithJuice WRLDFeid, Justin QuilesBausa, JujuTaylor SwiftblackbearMustardBTSJason Mraz5 Seconds of SummerTaylor SwiftDua LipaTaylor SwiftRod WavePolo GS1mbaHeadie One, DrakeDua LipaRauw Alejandro, Chencho CorleoneJason Derulo, Puri, JhorrmountainAya NakamuratwocolorsTaylor SwiftKygo, Whitney HoustonJuanfranNLE ChoppaPost MaloneTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftDaBabyTaylor SwiftDoja Cat6ix9ineApache 207VIZE, Tom GregoryMegan Thee StallionTaylor SwiftTaylor SwiftTaylor SwiftA$AP FergApache 207Bonez MCFuture, Lil Uzi VertTaylor SwiftJuice WRLDNLE ChoppaJ BalvinEl Alfa, Chael ProduciendoRauw AlejandroTy Dolla $ignJ BalvinBillie EilishJ. ColeCapital Bra, Clueso, KC RebellThe Kid LAROIJuice WRLDOne DirectionUfo361, Sonus030Juice WRLDJuice WRLDJuice WRLDDripReportLil BabyOne DirectionLogicStaySolidRocky, Lil Uzi VertJuice WRLDJuice WRLDJuice WRLDJuice WRLDJuice WRLDTrevor DanielJuice WRLDLil TeccaMyke TowersLucianoBad Bunny6ix9ineLil Nas X, Billy Ray CyrusKid CudiAnuel AA, Daddy Yankee, KAROL G, Ozuna, J BalvinDalex, Lenny Tavárez, Chencho Corleone, Juhn, Dímelo FlowBad Bunny, SechJustin BieberRoddy RicchDoja CatPost MaloneDaBabyDímelo Flow, Arcangel, SechJuice WRLDJuice WRLDJuice WRLDKontra KKanye West, Travis ScottPop SmokeRed Velvet - IRENE & SEULGI6ix9ineAnuel AASam FischerPop SmokeY2K, bbno$Pop SmokePop SmokePop SmokePop SmokePop SmokePop SmokePop SmokePop SmokePop SmokeSleepy Hallow, FousheéTyla YawehPop SmokeBad Bunnyiann diorJhay Cortez, J Balvin, Bad BunnyAnuel AAImagine DragonsRauw Alejandro, Chencho Corleone, KEVVO, Bryant Myers, Lyanno, DalexPost MaloneJourneyBeyoncéMiksu / Macloud, Summer Cem, Luciano, JamuleAva MaxKaty PerryLil BabyLil Uzi VertTWICEMegan Thee StallionBring Me The HorizonJonas BrothersLauvPanic! At The DiscoDrakeDoja CatBoomdabash, Alessandra AmorosoKhalid, DisclosureDon ToliverPashanimBLACKPINKHarry StylesSelena GomezMaroon 5Bad Bunny, Don OmarTygaBonez MCCapital Bra, BozzaAnuel AAA Boogie Wit da HoodieJ. ColeBoshAlida, Robin SchulzLady GagaNLE ChoppaAlexander 23MEDUZA, GoodboysNiackBad Bunny, Daddy YankeePUBLICDaBabyPop Smoke, Rowdy RebelShabloUfo361, CÉLINELil Uzi VertMadison BeerNatalie TaylorNAVBad BunnyBad BunnyKygo, Zara Larsson, TygaCamila CabelloAlec BenjaminPARTYNEXTDOOR, RihannaApache 207XXXTENTACIONKC Rebell, Summer CemSam SmithChildish GambinoRauw Alejandro, FarrukoBad Bunny, Nicky JamShawn MendesJonas BrothersBad Bunny, TainyFutureLil Uzi VertXXXTENTACIONYNW MellyTwenty One PilotsLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaKygo, Kim PetrasKC Rebell, Summer CemKALIM, Ufo361Lil YachtyLil YachtyBonez MCKygo, Zak AbelApache 207Agust DGunnaThe WeekndGunnaCapital BraGunnaPost MaloneYandel, Bad BunnyJonas BrothersBad Bunny, Zion & LennoxSiaIUHalsey24kGoldnVicetone, Tony IgyThe WeekndTravis ScottTones And IArcangel, Sech, Romeo SantosjxdnSech, Daddy YankeeNicky Jam, Daddy YankeeFutureDrakeFuturePolo G, Stunna 4 Vegas, NLE Choppa, Mike WiLL Made-ItGusttavo LimaMigosPolo GBad BunnyG Herbo, Juice WRLD, Lil Uzi Vert, Chance the RapperTrippie Redd, PARTYNEXTDOORKina, Adriana ProenzaBad BunnyBad BunnyLil TjayBad Bunny, GabrielaBanda MS de Sergio Lizárraga, Snoop DoggCapital Bra, LoredanaBad BunnyDrakeAsheKehlaniTravis Scottbenny blancoYNW MellySam SmithBillie EilishFuture, Drake, Young ThugDrakeDrakeDrakeDrakeDrakeDrakeDrakeDrakeDrakeNAV, GunnaSelena GomezAli GatieUfo361DaBabyAnuel AADrakeCamilo, Evaluna MontanerPlayboi CartiTory LanezRauw Alejandro, Anuel AA, Natti Natasha, Farruko, LunayBROCKHAMPTONShirin DavidTravis ScottKSILil Uzi VertShakira, Anuel AAThe 1975Alan Walker, Ava MaxCamilo, Pedro CapóEllie GouldingG-EazyJ BalvinDaBabyDaBabyDaBabyLil Uzi VertRvssian, Anuel AA, Juice WRLDKygo, Sasha Alex SloanLil YachtyDaBabyKAROL G, Anuel AADominic FikeTory LanezTory LanezBonez MCSamraSam SmithITZYThe Chainsmokers, ILLENIUM, Lennon StellaRod WaveLunay, Myke Towers, Ozuna, Chencho Corleone, Rauw AlejandroPolo G, Stunna 4 VegasSub UrbanLizzoJustin BieberDemi Lovato5 Seconds of SummerBad BunnyThe WeekndLuísa SonzaLil BabyDua LipaBazziDua LipaDua LipaDua LipaThe WeekndThe WeekndDua LipaShiva, Eiffel 65Zuna, Loredana, SRNOThe Weeknd5 Seconds of SummerThe WeekndThe WeekndThe WeekndUfo361Bad Bunny, YaviahJhay Cortez, Anuel AA, J BalvinLittle Mix5 Seconds of SummerThe WeekndThe WeekndJ BalvinJ BalvinJ BalvinJ Balvin, Sky RompiendoLil Uzi VertLil Uzi VertNiall HoranLil Uzi VertJ Balvin, Mr EaziDaBabySelena GomezDardan, Monet192Bad BunnyChristian NodalJhené AikoBad BunnyBad Bunny, Anuel AALil Uzi VertLil Uzi Vert, 21 SavageDon ToliverLil Uzi VertBad Bunny, Duki, Pablo Chill-ELil Uzi VertNinhoBad Bunny, Ñengo FlowLil Uzi VertLil Uzi VertBad BunnyLil Uzi VertBad Bunny, MoraLil Uzi VertNiall HoranSZA, Justin TimberlakeNicky Jam, Anuel AATygaLil Uzi VertLauvLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertBTSTones And ITainyBad BunnyUfo361Henrique & JulianoLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertResidenteLil Uzi VertLil Uzi VertBTSBad Bunny, Kendo Kaponi, ArcangelLauvLil BabyGunnaBazziLauv, Troye SivanA Boogie Wit da HoodieMyke TowersBad Bunny, Myke TowersDaddy Yankee, SechEd SheeranPost MaloneLauvLunay, Ozuna, Anuel AASelena GomezDaBabyLauv, LANYLil Uzi VertLil BabyLil BabyLil BabyBTSApache 207Dalex, Lenny Tavárez, Anitta, Natti Natasha, Farruko, Justin QuilesArcangel, Bad BunnyDaddy YankeeLil Uzi VertTOKYO’S REVENGEStormzyFutureBTSCapital Bra, SamraMartin GarrixblackbearJ Balvin, Bad BunnyTaylor SwiftRich Music LTD, Sech, Dalex, Justin Quiles, Lenny Tavárez, Feid, Wisin, ZionLunay, Daddy Yankee, Bad BunnySHAEDLizzoBillie EilishBTSBTSBTSBTSBTSBTSBTSBTSBTSBTSThiaguinho MT, Mila, JS o Mão de OuroRich Music LTD, Sech, Dalex, Justin Quiles, Lenny Tavárez, FeidEminemBillie EilishPEDRO SAMPAIO, Felipe Original, JS o Mão de OuroK CAMPSech, OzunaMajor Lazer, DiploUfo361Reik, J Balvin, Lalo EbrattBillie EilishDalex, SechMigos, Travis Scott, Young ThugJustin BieberJustin BieberJustin BieberJustin BieberJustin BieberJustin BieberJustin BieberTame ImpalaJustin BieberJustin BieberLucianoJustin BieberTame ImpalaJustin Bieber5 Seconds of SummerA Boogie Wit da HoodieJustin BieberKygo, Sandro CavazzaJoker Bra, VIZETame ImpalaMac MillerBillie EilishTaylor SwiftTame ImpalaJustin BieberBillie EilishSam SmithJustin Bieber, QuavoNicki MinajAnt SaundersAnne-MarieTravis ScottLizzoLil WayneJustin Bieber, KehlaniROSALÍA, OzunaJustin Quiles, Natti Natasha, FarrukoTyler, The CreatorPiso 21, Christian NodalDJ Snake, J BalvinRed VelvetDaBabyROSALÍA, J Balvin, El GuinchoJonas BrothersKhalidKhalidTravis Scott, Young ThugSamraDaddy Yankee, SnowJ. ColeSech, Ozuna, Anuel AA, Darell, Nicky JamArizona ZervasA Boogie Wit da HoodieEminemSamraMatthew WilderJuju, Loredana, Miksu / MacloudHalseyKSIRiton, Oliver HeldensShakiraCamila CabelloMeek MillTaylor SwiftLil Nas XBillie EilishJ. Cole, Young ThugYNW MellyEminemEminemMac MillerHenrique & JulianoEminemGzuzEminemSamra, ELIFMegan Thee StallionSelena GomezMurda, EzhelJuice WRLDMalumaSam FeldtEminemEminemMac MillerMac MillerEminemMac MillerEminemEminemEminemEminemEminemMac MillerEminemMac MillerEminemEminemEminemHalseyMac MillerMac MillerMac MillerUfo361, FutureMac MillerGambiMaes, BoobaSelena GomezSelena GomezSelena GomezSelena GomezSelena GomezKhalidNiall HoranIdina Menzel, AURORASelena GomezSelena GomezLil MoseyPost MaloneRoddy RicchRoddy RicchMegan Thee StallionMabelTrippie Redd, DaBabyPedro Capó, FarrukoSelena GomezSelena GomezAnne-MarieDJ SnakeThe Chainsmokers, KygoJACKBOYS, Sheck WesDon ToliverJACKBOYS, Travis ScottFrench Montana24kGoldnApache 207Katy PerryCalvin HarrisOzunaSHAED, ZAYNJACKBOYS, Pop Smoke, Travis ScottDoja CatJACKBOYSAnitta, Lexa, Luísa SonzaLil Nas XJuice WRLDGradur, Heuss L'enfoiréDua LipaJorge & MateusCamila CabelloDadá Boladão, Tati Zaqui, OIKTaylor Swift"

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in _ensure_numeric(x)
   1606             try:
-> 1607                 x = complex(x)
   1608             except ValueError as err:

ValueError: complex() arg is a malformed string

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/var/folders/8j/gshrlmtn7dg4qtztj4d4t_w40000gn/T/ipykernel_60487/3328112774.py in <module>
----> 1 df2.apply(lambda s: s-s.mean(), axis=0)

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwargs)
   8738             kwargs=kwargs,
   8739         )
-> 8740         return op.apply()
   8741 
   8742     def applymap(

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/apply.py in apply(self)
    686             return self.apply_raw()
    687 
--> 688         return self.apply_standard()
    689 
    690     def agg(self):

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/apply.py in apply_standard(self)
    810 
    811     def apply_standard(self):
--> 812         results, res_index = self.apply_series_generator()
    813 
    814         # wrap results

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/apply.py in apply_series_generator(self)
    826             for i, v in enumerate(series_gen):
    827                 # ignore SettingWithCopy here in case the user mutates
--> 828                 results[i] = self.f(v)
    829                 if isinstance(results[i], ABCSeries):
    830                     # If we have a view on v, we need to make a copy because

/var/folders/8j/gshrlmtn7dg4qtztj4d4t_w40000gn/T/ipykernel_60487/3328112774.py in <lambda>(s)
----> 1 df2.apply(lambda s: s-s.mean(), axis=0)

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/generic.py in mean(self, axis, skipna, level, numeric_only, **kwargs)
  10749         )
  10750         def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs):
> 10751             return NDFrame.mean(self, axis, skipna, level, numeric_only, **kwargs)
  10752 
  10753         setattr(cls, "mean", mean)

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/generic.py in mean(self, axis, skipna, level, numeric_only, **kwargs)
  10368     def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs):
  10369         return self._stat_function(
> 10370             "mean", nanops.nanmean, axis, skipna, level, numeric_only, **kwargs
  10371         )
  10372 

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/generic.py in _stat_function(self, name, func, axis, skipna, level, numeric_only, **kwargs)
  10353             )
  10354         return self._reduce(
> 10355             func, name=name, axis=axis, skipna=skipna, numeric_only=numeric_only
  10356         )
  10357 

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/series.py in _reduce(self, op, name, axis, skipna, numeric_only, filter_type, **kwds)
   4390                 )
   4391             with np.errstate(all="ignore"):
-> 4392                 return op(delegate, skipna=skipna, **kwds)
   4393 
   4394     def _reindex_indexer(

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in _f(*args, **kwargs)
     92             try:
     93                 with np.errstate(invalid="ignore"):
---> 94                     return f(*args, **kwargs)
     95             except ValueError as e:
     96                 # we want to transform an object array

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in f(values, axis, skipna, **kwds)
    154                     result = alt(values, axis=axis, skipna=skipna, **kwds)
    155             else:
--> 156                 result = alt(values, axis=axis, skipna=skipna, **kwds)
    157 
    158             return result

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in new_func(values, axis, skipna, mask, **kwargs)
    409             mask = isna(values)
    410 
--> 411         result = func(values, axis=axis, skipna=skipna, mask=mask, **kwargs)
    412 
    413         if datetimelike:

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in nanmean(values, axis, skipna, mask)
    664 
    665     count = _get_counts(values.shape, mask, axis, dtype=dtype_count)
--> 666     the_sum = _ensure_numeric(values.sum(axis, dtype=dtype_sum))
    667 
    668     if axis is not None and getattr(the_sum, "ndim", False):

~/miniconda3/envs/math10s22/lib/python3.7/site-packages/pandas/core/nanops.py in _ensure_numeric(x)
   1608             except ValueError as err:
   1609                 # e.g. "foo"
-> 1610                 raise TypeError(f"Could not convert {x} to numeric") from err
   1611     return x
   1612 

TypeError: Could not convert MåneskinThe Kid LAROIOlivia RodrigoEd SheeranLil Nas XLil Nas XDoja CatRauw AlejandroBad BunnyMåneskinDua LipaJ Balvin, Maria BecerraBTSJustin BieberBTSOlivia RodrigoOlivia RodrigoThe WeekndNio Garcia, J Balvin, Bad BunnyDoja CatMora, Bad Bunny, SechDoja CatOlivia RodrigoGlass AnimalsThe WeekndOlivia RodrigoFarrukoPost MaloneRiton, NightcrawlersMasked WolfBruno Mars, Anderson .Paak, Silk SonicCamila CabelloOlivia RodrigoSebastian Yatra, Myke TowersHarry StylesPolo GDoja Cat, The WeekndSech, Jhay CortezBad Bunny, Jhay CortezTINI, Maria BecerraOlivia RodrigoJ Balvin, KAROL G, Nicky Jam, Crissin, Totoy El Frio, Natan & ShanderBTSTiëstoGalantis24kGoldnTiago PZK, LIT killahWisin, Jhay Cortez, Anuel AA, Los Legendarios, Myke TowersBella PoarchBizarrap, Nicky JamMarc Seguí, Rauw Alejandro, Pol GranchBillie EilishMajestic, Boney M.MarshmelloSurf CurseJoão GomesRauw Alejandro, Mr. NaisgaiMaroon 5OneRepublicMegan Thee StallionATB, Topic, A7SOlivia RodrigoThe WeekndGiveonDua LipaTrinidad CardonaThe NeighbourhoodMalumaLewis CapaldiSmileySleepy HallowKAROL G, Mariah AngeliqJustin Quiles, Chimbala, Zion & LennoxShouseMåneskinKali UchisGera MX, Christian NodalLos Legendarios, Wisin, Jhay CortezTones And IThe Kid LAROIDrakeBo BurnhamDua LipaTravis Scott, HVMEJoel CorryJoel Corry, RAYE, David GuettaJustin Wellington, Small JamBelly, The Weeknd, Young ThugDuncan LaurenceMora, Jhay CortezAriana GrandePost MaloneRAF Camora, Bonez MCNatti Natasha, Becky GJ Balvin, SkrillexDoja CatWILLOWDaveLewis CapaldiDua LipaMadison BeerBANDIDOImagine DragonsInternet MoneyBruno MarsSAINt JHNSechBecky G, El AlfaIngrataxBillie EilishPost Malone, Swae LeedhruvDoja CatCalvin HarrisLuan SantanaEd SheeranShawn Mendes, Camila CabelloJustin BieberEd SheeranMYA, TINI, DukiBad Bunny, ROSALÍADaBabyConan GrayTate McRaeAviciiVance JoyNirvanaOlivia RodrigoThe NeighbourhoodJoão GomesTrippie ReddMaroon 5Tom OdellJamie MillerHozierTom GrennanGusttavo LimaCardi BMalumaKhalidQueenMyke Towers, JuhnMEDUZATravis ScottOfenbachCamilo, Shawn MendesLady Gaga, Bradley CooperCochise, $NOTMari FernandezOneRepublicColdplayEmilia, DukiJoão Gomes, Vitor FernandesAviciiMatheus Fernandes, DilsinhoVegedreamPop SmokeAURORADaBabyDaBabyJuice WRLDLil Tjay, 6LACKBillie EilishP!nk, Willow Sage HartPop SmokeOlivia RodrigoCardi BThe KillersThe PoliceFleetwood MacJames ArthurNormaniPop SmokePop SmokePowfu, beabadoobeeAnne-Marie, Niall HoranQueenDrake, WizKid, KylaHarry StylesSarah CothranWalker HayesRauw AlejandroJohn LegendPolo GPop SmokeSaweetieThe WeekndSZAAnne-Marie, Little MixBad BunnyAriana GrandeBlxst, TygaMC Zaquin, MC RickTopic, A7SLuísa SonzaRoddy RicchDaveEminemPop SmokePop SmokeTrippie Redd, Lil Uzi VertPop SmokePop SmokeKSIPop SmokePop SmokeTyler, The CreatorPashanimTion Wayne, Russ MillionsPop SmokeNio Garcia, Flow La MovieBLANCO, Sfera EbbastaRegardBillie EilishJohn MayerImagine DragonsMc Davi, Mc Pedrinho, Mc Don JuanInternet MoneyImagine DragonsDua LipaBTSSechSelena GomezBasOlivia RodrigoIsrael & Rodolffo, Wesley SafadãoTWICEBIAKane Brown, blackbearAlex Rose, Rauw AlejandroDj Guuga, DJ IvisMaluma, Beéle, Rauw Alejandro, Mambo Kingz, DJ Luian, DarellRauw AlejandroThe Chainsmokers, HalseyOasisBrent FaiyazDoja CatBig Red MachineTyler, The CreatorBo BurnhamDJ KhaledStarBoi3LordeBillie EilishShirin DavidCJIsrael & RodolffoMiley CyrusGym Class HeroesRauw Alejandro, Anuel AAsangiovanniBizarrap, Eladio CarrionArctic MonkeysTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorTyler, The CreatorDoja CatTyler, The CreatorTyler, The CreatorDoja CatMigosDoja CatDoja CatFedez, Achille LauroJ Balvin, Dua Lipa, Bad BunnyJawsh 685, Jason DeruloCrissin, Totoy El Frio, Natan & ShanderBozaTate McRae, KhalidSoso ManessJ. ColeJ. ColeXXXTENTACIONPolo GRoddy RicchNathan EvansMacklemore & Ryan LewisJustin BieberMachine Gun KellyBruno MarsTravis ScottDua LipaDrakeMartin GarrixRochy RD, Myke Towers, Nicki NicoleLinkin ParkJ. ColeTravis ScottThe Chainsmokers, ColdplayRegard, Troye Sivan, Tate McRaeMigosPolo GPolo GMaroon 5MigosAva MaxMigosBlack Eyed Peas, ShakiraPolo GMigosBillie EilishBad BunnyMC Kevin o ChrisColdplayLil Nas XPolo GLady GagaLil Baby, Lil DurkJohn MayerLil Baby, Lil DurkTOMORROW X TOGETHER, SeoriJ. ColeLil TeccaYoung Stoner Life, Young Thug, GunnaManuel Turizo, Rauw Alejandro, Myke TowersHarry StylesMåneskinKAROL GAshnikkoEminemAlok, Mc Don Juan, Dj GBRJuice WRLDJuice WRLDBTSMalu, DJ Lucas BeatEminemLil MoseyGotye, KimbraJustin BieberMc Poze do Rodo, Neo Beats, MainstreetJ. ColeBTSBTSBarbara PraviTwenty One PilotsTwenty One PilotsJ. ColeNicki MinajBlind ChannelGo_AITZYJ. ColeDrakeJoyner Lucas, Lil BabyBeach BunnyGjon's TearsLil TjayDreamDaði FreyrTwenty One PilotsJ. ColeJ. ColeJ. ColeJ. ColeJ. ColeJ. ColeThe Kid LAROIBizarrap, Snow Tha ProductNio Garcia, Casper Magico, Ozuna, Wisin & Yandel, Myke Towers, Flow La MovieMARINAHarry StylesMyke TowersMilly, Farruko, Nio Garcia, Jay Wheeler, AmenazzyDaddy YankeeJustin BieberGym Class HeroesJP SaxeDJ KhaledRuss Millions, Tion WayneBillie EilishDon ToliverBizarrap, L-GanteLil Nas XPink Sweat$Future187 Strassenbande, Bonez MC, FrauenarztJuice WRLDNicky Jam, Romeo SantosRaí Saia RodadaCamilo, Evaluna MontanerJuice WRLDJuice WRLDJorge & MateusElyOttoBaby KeemMachine Gun KellyDJ KhaledDJ KhaledAnittaROSÉTaylor SwiftBillie EilishJ Balvin, KhalidDemi LovatoPooh ShiestyLil TjayWisin, Myke Towers, Los LegendariosJustin BieberH.E.R.HVMERitt MomneyDiego & Victor Hugo, Bruno & MarroneJames ArthurShawn MendesThe WeekndXXXTENTACIONMimi WebbblackbearBruno MarsKAROL G, Anuel AA, J BalvinTwenty One PilotsYoung Stoner Life, Young Thug, GunnaYoung Stoner Life, Young Thug, GunnaTaylor SwiftWesley Safadão, Os Barões Da PisadinhaOs Barões Da PisadinhaTaylor SwiftArctic MonkeysEd SheeranJ Balvin, Bad BunnyTaylor SwiftTaylor SwiftDMXTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftDMXTaylor SwiftTaylor SwiftTaylor SwiftSebastian Yatra, GuaynaaSech, Daddy Yankee, J Balvin, ROSALÍA, FarrukoTaylor SwiftTaylor SwiftKHEA, DukiDemi LovatoROSÉSam Fischer, Demi LovatoPop SmokeKevin Roldan, Bryant Myers, LyannoJason DeruloJustin BieberAriana GrandeMother MotherDJ IvisRusherking, KHEA, Duki, Maria Becerra, LIT killah, Tiago PZKMaroon 5, Wiz KhalifaJustin BieberJustin BieberJack Harlowa-haCamilo, El AlfaJ BalvinJustin BieberJustin BieberKAROL G, Nicki MinajOzuna, J Balvin, Chencho CorleoneJustin BieberZoe WeesDrakeDJ Ivis, Tarcísio do AcordeonJason Derulo, NukaJustin BieberThe Weeknd, Daft PunkFarrukoHugo & GuilhermeJustin BieberJustin BieberLana Del ReyNicky Jam, Myke TowersLana Del ReyMaluma, Lenny TavárezCamiloCamiloHippie SabotageJustin QuilesSelena GomezKSIDJ SnakeSiaMachine Gun KellyJay Wheeler, DJ Nelson, Myke TowersRobin SchulzDoja CatXXXTENTACIONTame ImpalaThe Weeknd, Daft PunkPop SmokeBANNERSPamungkasBLACKPINKNF, HopsinMadamePop SmokeJuice WRLDFrancesca Michielin, FedezAnuel AA, OzunaBooba, JSXLil BabyLele PonsOfenbach, QuarterheadLil PeepBØRNSConan GrayPost MaloneAriana GrandeC. Tangana, Niño de Elche, La HúngaraThe Kid LAROIJustin QuilesArizona ZervasPost MaloneC. Tangana, Ed MaverickHalseyBad BunnyJustin BieberClairoEd SheeranBausa, Apache 207NFShawn MendesSabrina CarpenterJack HarlowSara KaysJason Derulo, Maroon 5Tones And IOzuna, CamiloAriana GrandeEd SheeranKAROL GBizarrap, Nathy PelusoMaluma, The WeekndRauw AlejandroTarcísio do AcordeonXXXTENTACIONEd SheeranDrakeThe WeekndSurf MesaOasisXXXTENTACIONJuice WRLDBillie EilishSia, David GuettaThe Weekndbenny blancoThe WeekndMiley CyrusMartin GarrixBring Me The HorizonMalumaKawe, Mc Lele JPThe WeekndAriana GrandeDean LewisMegan Thee StallionJerry DiKASIMIR1441, badmómzjay, WILDBWOYSBrent Faiyaz, DJ DahiZAYNOlivia RodrigoAshnikkoMorgan WallenNio Garcia, Anuel AA, Myke Towers, Brray, JuankaAnuel AA, OzunaMigrantes, AlicoMorgan WallenSelena GomezJack HarlowSam Smith347aidanRauw Alejandro, J BalvinTaylor SwiftChris Brown, Young ThugJuice WRLD, The Kid LAROIAnne-Marie, KSI, Digital Farm AnimalsLuísa Sonza, Pabllo Vittar, AnittaErica BanksAva MaxBLACKPINKOzunaFousheéMorgan WallenMorgan WallenMorgan WallenBad BunnySech, J BalvinPop SmokeMorgan WallenMorgan WallenOs Barões Da PisadinhaBLACKPINKMarshmelloDua Lipa, AngèleApache 207Taylor SwiftSurfacesPetter Ferraz, Menor NicoMarshmello, BastilleQueenJ BalvinOs Barões Da Pisadinha, Xand AviãoKid CudiMEDUZA, Becky Hill, GoodboysTWICECORPSE, Savage Ga$pMariah CareyWham!Ariana GrandeBrenda LeeBobby HelmsMichael BubléAndy WilliamsKelly ClarksonJosé FelicianoDean MartinFrank SinatraJustin BieberThe RonettesBand AidPaul McCartneyMichael BubléJohn Lennon, Yoko OnoNat King ColeBing Crosby, Ken Darby Singers, John Scott Trotter & His OrchestraPlayboi CartiBurl IvesThe PoguesShakin' StevensElvis PresleyChuck BerryThe Jackson 5Kylie MinoguePerry Como, The Fontane SistersDarlene LoveElton JohnKid CudiJonas EsticadoJorge & MateusDaryl Hall & John OatesColdplaySam SmithSiaBritney SpearsBrett EldredgeJonas BrothersAva MaxGwen StefaniEminemNat King ColeMichael BubléIdina MenzelTaylor SwiftThe Jackson 5Eartha Kitt, Henri Rene & His OrchestraMykola Dmytrovych Leontovych, John WilliamsTaylor SwiftStevie WonderShawn MendesDean MartinBruce SpringsteenLeona LewisThe Beach BoysLiam PayneMeghan TrainorDean MartinFrank SinatraFrank SinatraMariah CareyBing CrosbyPentatonixDonny HathawayTony BennettTaylor SwiftKaty Perry*NSYNCTaylor SwiftEaglesMeghan TrainorTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftKid CudiKid CudiKid CudiKid CudiKid CudiKid CudiKid CudiBad BunnyKid CudiKid CudiTaylor SwiftJuice WRLDShawn MendesThe WeekndTory Lanez, Jack HarlowBad BunnyLil BabyMiley CyrusBTSsalem ileseBad Bunny, Jowell & Randy, Ñengo FlowBad BunnyThe Kid LAROIStudio Killers24kGoldnBad BunnyBad BunnyBad BunnyBad BunnyBad Bunny, ABRABad BunnyBad BunnyPaul McCartneyBTSBTSBTSBTSMiley CyrusTrio VegabajeñoMiley CyrusJhay Cortez, Bad BunnyBTSSfera EbbastaClean Bandit, MabelChristian Nodal, Ángela AguilarSfera EbbastaMaster KGSfera EbbastaAya NakamuraThe Kid LAROIJuice WRLDBLACKPINKJawsh 685, Jason DeruloJustin TimberlakeSfera Ebbasta21 Savage, Metro BoominWallowsDan + ShayVedoManuel TurizoStaySolidRockyFuture, Lil Uzi VertKane BrownK/DA, Madison Beer, (G)I-DLE, Lexie Liu, Jaira Burns, Seraphine, League of LegendsRauw AlejandroFuture, Lil Uzi VertOctavian, SkeptaAriana GrandeTy Dolla $ignLittle MixMAXFuture, Lil Uzi VertNelly Furtado, TimbalandDJ KhaledAriana GrandeLabrinthAnuel AA, Bad BunnyKinaDDGLuke CombsJojiDaddy Yankee, Anuel AA, Kendo KaponiBillie EilishCali Y El Dandee, Danna PaolaAriana GrandeAriana GrandeAriana GrandeThe Kid LAROIKHEAMalumaOzuna, KAROL G, Myke Towers21 Savage, Metro BoominPop SmokeAriana GrandeAriana GrandeEd SheeranCamiloDon ToliverJ BalvinAriana GrandeAriana GrandeAriana GrandeMichael JacksonSam SmithBonez MCSam SmithAC/DCAnittaMoney ManSechTravis ScottBLACKPINKBig SeanAriana GrandeBlack Eyed Peas, Ozuna, J. Rey SoulLauv, Conan GrayMarshmello, Demi LovatoTHE SCOTTS, Travis Scott, Kid CudiTrueno, Bizarrap, Taiu, TATOOLPassengerMelanie MartinezKygo, OneRepublicAdeleAli GatieCurtis WatersBLACKPINKG-Eazy13 Organisé, SCH, Kofs, Jul, Naps, Soso Maness, Elams, Solda, HouariBLACKPINKBebe RexhaROSALÍACamiloBad BunnyLana Del ReyGunnaRauw Alejandro, Dalex, Lenny TavárezNoah CyrusLewis CapaldiBLACKPINKBENEE, Gus Dapperton21 Savage, Metro BoominZAYNMachine Gun KellyNiackFeid, J Balvin, Justin QuilesChris Brown21 Savage, Metro Boomin21 Savage, Metro Boomin21 Savage, Metro BoominBryson Tiller21 Savage, Metro Boomin21 Savage, Metro Boomin21 Savage, Metro BoominInternet MoneyJoji21 Savage, Metro BoominWhoHeem21 Savage, Metro Boomin21 Savage, Metro BoominJojiJojiJoji, DiploPolo GMachine Gun KellyJojiJojiJojiBea MillerSaweetieJojiJoji, BENEECalvin HarrisJuice WRLD, Polo GMachine Gun KellyHarry NachJack HarlowKendrick Lamar, Jay RockInternet Money, DiploEarth, Wind & FireRegard, RAYEPolo GDamso, HamzaDamsoTaylor SwiftJuice WRLDJuice WRLDLil TeccaDrake6ix9ineDua LipaKygo, Donna SummerAva MaxAva MaxOzuna, Doja Cat, SiaSZA, The Neptunes, Pharrell Williams, Ty Dolla $ignMaroon 5MatuêBonez MCAlex Rose, Rafa PabönLil BabyBonez MC, MaxwellMiley CyrusDoja CatHeadie OneNeaBeyoncé, Megan Thee StallionBig SeanSaweetieITZYTravis ScottMalumaRobin Schulz, WesK/DA, (G)I-DLE, Wolftyla, Bea Miller, League of LegendsMc Zaac, Anitta, TygaPeach Tree RascalsTaylor SwiftBlack Eyed Peas, J BalvinKitschKrieg, Jamule, SFRKygo, Tina TurnerKaty PerryConkarahCordaeJACKBOYS, Travis ScottJowell & Randy, J BalvinAnuel AALady GagaRod WaveJuice WRLDJustin Quiles, Daddy Yankee, El AlfaInternet Money, Gunna, Don Toliver, NAVCapital Bra, CroBTSSam SmithJuice WRLDFeid, Justin QuilesBausa, JujuTaylor SwiftblackbearMustardBTSJason Mraz5 Seconds of SummerTaylor SwiftDua LipaTaylor SwiftRod WavePolo GS1mbaHeadie One, DrakeDua LipaRauw Alejandro, Chencho CorleoneJason Derulo, Puri, JhorrmountainAya NakamuratwocolorsTaylor SwiftKygo, Whitney HoustonJuanfranNLE ChoppaPost MaloneTaylor SwiftTaylor SwiftTaylor SwiftTaylor SwiftDaBabyTaylor SwiftDoja Cat6ix9ineApache 207VIZE, Tom GregoryMegan Thee StallionTaylor SwiftTaylor SwiftTaylor SwiftA$AP FergApache 207Bonez MCFuture, Lil Uzi VertTaylor SwiftJuice WRLDNLE ChoppaJ BalvinEl Alfa, Chael ProduciendoRauw AlejandroTy Dolla $ignJ BalvinBillie EilishJ. ColeCapital Bra, Clueso, KC RebellThe Kid LAROIJuice WRLDOne DirectionUfo361, Sonus030Juice WRLDJuice WRLDJuice WRLDDripReportLil BabyOne DirectionLogicStaySolidRocky, Lil Uzi VertJuice WRLDJuice WRLDJuice WRLDJuice WRLDJuice WRLDTrevor DanielJuice WRLDLil TeccaMyke TowersLucianoBad Bunny6ix9ineLil Nas X, Billy Ray CyrusKid CudiAnuel AA, Daddy Yankee, KAROL G, Ozuna, J BalvinDalex, Lenny Tavárez, Chencho Corleone, Juhn, Dímelo FlowBad Bunny, SechJustin BieberRoddy RicchDoja CatPost MaloneDaBabyDímelo Flow, Arcangel, SechJuice WRLDJuice WRLDJuice WRLDKontra KKanye West, Travis ScottPop SmokeRed Velvet - IRENE & SEULGI6ix9ineAnuel AASam FischerPop SmokeY2K, bbno$Pop SmokePop SmokePop SmokePop SmokePop SmokePop SmokePop SmokePop SmokePop SmokeSleepy Hallow, FousheéTyla YawehPop SmokeBad Bunnyiann diorJhay Cortez, J Balvin, Bad BunnyAnuel AAImagine DragonsRauw Alejandro, Chencho Corleone, KEVVO, Bryant Myers, Lyanno, DalexPost MaloneJourneyBeyoncéMiksu / Macloud, Summer Cem, Luciano, JamuleAva MaxKaty PerryLil BabyLil Uzi VertTWICEMegan Thee StallionBring Me The HorizonJonas BrothersLauvPanic! At The DiscoDrakeDoja CatBoomdabash, Alessandra AmorosoKhalid, DisclosureDon ToliverPashanimBLACKPINKHarry StylesSelena GomezMaroon 5Bad Bunny, Don OmarTygaBonez MCCapital Bra, BozzaAnuel AAA Boogie Wit da HoodieJ. ColeBoshAlida, Robin SchulzLady GagaNLE ChoppaAlexander 23MEDUZA, GoodboysNiackBad Bunny, Daddy YankeePUBLICDaBabyPop Smoke, Rowdy RebelShabloUfo361, CÉLINELil Uzi VertMadison BeerNatalie TaylorNAVBad BunnyBad BunnyKygo, Zara Larsson, TygaCamila CabelloAlec BenjaminPARTYNEXTDOOR, RihannaApache 207XXXTENTACIONKC Rebell, Summer CemSam SmithChildish GambinoRauw Alejandro, FarrukoBad Bunny, Nicky JamShawn MendesJonas BrothersBad Bunny, TainyFutureLil Uzi VertXXXTENTACIONYNW MellyTwenty One PilotsLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaLady GagaKygo, Kim PetrasKC Rebell, Summer CemKALIM, Ufo361Lil YachtyLil YachtyBonez MCKygo, Zak AbelApache 207Agust DGunnaThe WeekndGunnaCapital BraGunnaPost MaloneYandel, Bad BunnyJonas BrothersBad Bunny, Zion & LennoxSiaIUHalsey24kGoldnVicetone, Tony IgyThe WeekndTravis ScottTones And IArcangel, Sech, Romeo SantosjxdnSech, Daddy YankeeNicky Jam, Daddy YankeeFutureDrakeFuturePolo G, Stunna 4 Vegas, NLE Choppa, Mike WiLL Made-ItGusttavo LimaMigosPolo GBad BunnyG Herbo, Juice WRLD, Lil Uzi Vert, Chance the RapperTrippie Redd, PARTYNEXTDOORKina, Adriana ProenzaBad BunnyBad BunnyLil TjayBad Bunny, GabrielaBanda MS de Sergio Lizárraga, Snoop DoggCapital Bra, LoredanaBad BunnyDrakeAsheKehlaniTravis Scottbenny blancoYNW MellySam SmithBillie EilishFuture, Drake, Young ThugDrakeDrakeDrakeDrakeDrakeDrakeDrakeDrakeDrakeNAV, GunnaSelena GomezAli GatieUfo361DaBabyAnuel AADrakeCamilo, Evaluna MontanerPlayboi CartiTory LanezRauw Alejandro, Anuel AA, Natti Natasha, Farruko, LunayBROCKHAMPTONShirin DavidTravis ScottKSILil Uzi VertShakira, Anuel AAThe 1975Alan Walker, Ava MaxCamilo, Pedro CapóEllie GouldingG-EazyJ BalvinDaBabyDaBabyDaBabyLil Uzi VertRvssian, Anuel AA, Juice WRLDKygo, Sasha Alex SloanLil YachtyDaBabyKAROL G, Anuel AADominic FikeTory LanezTory LanezBonez MCSamraSam SmithITZYThe Chainsmokers, ILLENIUM, Lennon StellaRod WaveLunay, Myke Towers, Ozuna, Chencho Corleone, Rauw AlejandroPolo G, Stunna 4 VegasSub UrbanLizzoJustin BieberDemi Lovato5 Seconds of SummerBad BunnyThe WeekndLuísa SonzaLil BabyDua LipaBazziDua LipaDua LipaDua LipaThe WeekndThe WeekndDua LipaShiva, Eiffel 65Zuna, Loredana, SRNOThe Weeknd5 Seconds of SummerThe WeekndThe WeekndThe WeekndUfo361Bad Bunny, YaviahJhay Cortez, Anuel AA, J BalvinLittle Mix5 Seconds of SummerThe WeekndThe WeekndJ BalvinJ BalvinJ BalvinJ Balvin, Sky RompiendoLil Uzi VertLil Uzi VertNiall HoranLil Uzi VertJ Balvin, Mr EaziDaBabySelena GomezDardan, Monet192Bad BunnyChristian NodalJhené AikoBad BunnyBad Bunny, Anuel AALil Uzi VertLil Uzi Vert, 21 SavageDon ToliverLil Uzi VertBad Bunny, Duki, Pablo Chill-ELil Uzi VertNinhoBad Bunny, Ñengo FlowLil Uzi VertLil Uzi VertBad BunnyLil Uzi VertBad Bunny, MoraLil Uzi VertNiall HoranSZA, Justin TimberlakeNicky Jam, Anuel AATygaLil Uzi VertLauvLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertBTSTones And ITainyBad BunnyUfo361Henrique & JulianoLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertLil Uzi VertResidenteLil Uzi VertLil Uzi VertBTSBad Bunny, Kendo Kaponi, ArcangelLauvLil BabyGunnaBazziLauv, Troye SivanA Boogie Wit da HoodieMyke TowersBad Bunny, Myke TowersDaddy Yankee, SechEd SheeranPost MaloneLauvLunay, Ozuna, Anuel AASelena GomezDaBabyLauv, LANYLil Uzi VertLil BabyLil BabyLil BabyBTSApache 207Dalex, Lenny Tavárez, Anitta, Natti Natasha, Farruko, Justin QuilesArcangel, Bad BunnyDaddy YankeeLil Uzi VertTOKYO’S REVENGEStormzyFutureBTSCapital Bra, SamraMartin GarrixblackbearJ Balvin, Bad BunnyTaylor SwiftRich Music LTD, Sech, Dalex, Justin Quiles, Lenny Tavárez, Feid, Wisin, ZionLunay, Daddy Yankee, Bad BunnySHAEDLizzoBillie EilishBTSBTSBTSBTSBTSBTSBTSBTSBTSBTSThiaguinho MT, Mila, JS o Mão de OuroRich Music LTD, Sech, Dalex, Justin Quiles, Lenny Tavárez, FeidEminemBillie EilishPEDRO SAMPAIO, Felipe Original, JS o Mão de OuroK CAMPSech, OzunaMajor Lazer, DiploUfo361Reik, J Balvin, Lalo EbrattBillie EilishDalex, SechMigos, Travis Scott, Young ThugJustin BieberJustin BieberJustin BieberJustin BieberJustin BieberJustin BieberJustin BieberTame ImpalaJustin BieberJustin BieberLucianoJustin BieberTame ImpalaJustin Bieber5 Seconds of SummerA Boogie Wit da HoodieJustin BieberKygo, Sandro CavazzaJoker Bra, VIZETame ImpalaMac MillerBillie EilishTaylor SwiftTame ImpalaJustin BieberBillie EilishSam SmithJustin Bieber, QuavoNicki MinajAnt SaundersAnne-MarieTravis ScottLizzoLil WayneJustin Bieber, KehlaniROSALÍA, OzunaJustin Quiles, Natti Natasha, FarrukoTyler, The CreatorPiso 21, Christian NodalDJ Snake, J BalvinRed VelvetDaBabyROSALÍA, J Balvin, El GuinchoJonas BrothersKhalidKhalidTravis Scott, Young ThugSamraDaddy Yankee, SnowJ. ColeSech, Ozuna, Anuel AA, Darell, Nicky JamArizona ZervasA Boogie Wit da HoodieEminemSamraMatthew WilderJuju, Loredana, Miksu / MacloudHalseyKSIRiton, Oliver HeldensShakiraCamila CabelloMeek MillTaylor SwiftLil Nas XBillie EilishJ. Cole, Young ThugYNW MellyEminemEminemMac MillerHenrique & JulianoEminemGzuzEminemSamra, ELIFMegan Thee StallionSelena GomezMurda, EzhelJuice WRLDMalumaSam FeldtEminemEminemMac MillerMac MillerEminemMac MillerEminemEminemEminemEminemEminemMac MillerEminemMac MillerEminemEminemEminemHalseyMac MillerMac MillerMac MillerUfo361, FutureMac MillerGambiMaes, BoobaSelena GomezSelena GomezSelena GomezSelena GomezSelena GomezKhalidNiall HoranIdina Menzel, AURORASelena GomezSelena GomezLil MoseyPost MaloneRoddy RicchRoddy RicchMegan Thee StallionMabelTrippie Redd, DaBabyPedro Capó, FarrukoSelena GomezSelena GomezAnne-MarieDJ SnakeThe Chainsmokers, KygoJACKBOYS, Sheck WesDon ToliverJACKBOYS, Travis ScottFrench Montana24kGoldnApache 207Katy PerryCalvin HarrisOzunaSHAED, ZAYNJACKBOYS, Pop Smoke, Travis ScottDoja CatJACKBOYSAnitta, Lexa, Luísa SonzaLil Nas XJuice WRLDGradur, Heuss L'enfoiréDua LipaJorge & MateusCamila CabelloDadá Boladão, Tati Zaqui, OIKTaylor Swift to numeric
df2[numcols].apply(lambda s: s-s.mean(), axis=0)
Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 0.024003 0.166505 -0.073256 -0.121695 0.074296 13619.183172
1 -0.098997 0.130505 -0.075356 -0.210395 -0.036704 -56134.816828
2 -0.126997 0.030505 0.030344 0.086305 0.173296 -19793.816828
3 0.118003 0.263505 -0.088856 -0.201795 0.076296 33100.183172
4 0.046003 0.070505 -0.062156 -0.228395 0.379296 14059.183172
... ... ... ... ... ... ...
1551 0.072003 0.066505 -0.054256 -0.246085 0.093296 11379.183172
1552 -0.161997 0.236505 -0.038556 -0.008695 0.199296 -16010.816828
1553 0.075003 -0.110495 -0.093656 -0.064695 -0.120704 19366.183172
1554 0.142003 -0.083495 -0.064956 0.000305 0.366296 -45156.816828
1555 -0.241997 -0.030495 -0.059656 0.184305 -0.092704 23366.183172

1545 rows × 6 columns

Here we change the values in those numeric columns.

df2[numcols] = df2[numcols].apply(lambda s: s-s.mean(), axis=0)
df2[numcols].mean(axis=0)
Danceability    -8.738066e-17
Energy          -5.058880e-17
Speechiness      1.149746e-18
Acousticness     3.219287e-17
Valence          1.034771e-17
Duration (ms)   -6.630776e-12
dtype: float64

Just for practice with apply, here we do the same thing using a lambda function.

df2[numcols].apply(lambda s: s.mean(), axis=0)
Danceability    -8.738066e-17
Energy          -5.058880e-17
Speechiness      1.149746e-18
Acousticness     3.219287e-17
Valence          1.034771e-17
Duration (ms)   -6.630776e-12
dtype: float64

All of the entries are the same in df1 and df2, except for the top-left entry in df1 which we changed in a previous demonstration.

df1 == df2
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 False True True True True True True True True
1 True True True True True True True True True
2 True True True True True True True True True
3 True True True True True True True True True
4 True True True True True True True True True
... ... ... ... ... ... ... ... ... ...
1551 True True True True True True True True True
1552 True True True True True True True True True
1553 True True True True True True True True True
1554 True True True True True True True True True
1555 True True True True True True True True True

1545 rows × 9 columns

Rescaling 3: using scikit-learn

We can use the Python library scikit-learn to rescale these numeric columns.

  • Make a copy of df called df3.

  • Instantiate a StandardScaler object that will rescale mean but not standard deviation. Call the object scaler.

  • Fit scaler using the columns listed in numcols.

  • Transform those columns and put the result into df3.

df3 = df.copy()

Instead of importing all of scikit-learn, we will usually just import the specific tools we will need. In this case, we are importing only StandardScaler from the sklearn.preprocessing module.

from sklearn.preprocessing import StandardScaler
help(StandardScaler)
Help on class StandardScaler in module sklearn.preprocessing._data:

class StandardScaler(sklearn.base._OneToOneFeatureMixin, sklearn.base.TransformerMixin, sklearn.base.BaseEstimator)
 |  StandardScaler(*, copy=True, with_mean=True, with_std=True)
 |  
 |  Standardize features by removing the mean and scaling to unit variance.
 |  
 |  The standard score of a sample `x` is calculated as:
 |  
 |      z = (x - u) / s
 |  
 |  where `u` is the mean of the training samples or zero if `with_mean=False`,
 |  and `s` is the standard deviation of the training samples or one if
 |  `with_std=False`.
 |  
 |  Centering and scaling happen independently on each feature by computing
 |  the relevant statistics on the samples in the training set. Mean and
 |  standard deviation are then stored to be used on later data using
 |  :meth:`transform`.
 |  
 |  Standardization of a dataset is a common requirement for many
 |  machine learning estimators: they might behave badly if the
 |  individual features do not more or less look like standard normally
 |  distributed data (e.g. Gaussian with 0 mean and unit variance).
 |  
 |  For instance many elements used in the objective function of
 |  a learning algorithm (such as the RBF kernel of Support Vector
 |  Machines or the L1 and L2 regularizers of linear models) assume that
 |  all features are centered around 0 and have variance in the same
 |  order. If a feature has a variance that is orders of magnitude larger
 |  that others, it might dominate the objective function and make the
 |  estimator unable to learn from other features correctly as expected.
 |  
 |  This scaler can also be applied to sparse CSR or CSC matrices by passing
 |  `with_mean=False` to avoid breaking the sparsity structure of the data.
 |  
 |  Read more in the :ref:`User Guide <preprocessing_scaler>`.
 |  
 |  Parameters
 |  ----------
 |  copy : bool, default=True
 |      If False, try to avoid a copy and do inplace scaling instead.
 |      This is not guaranteed to always work inplace; e.g. if the data is
 |      not a NumPy array or scipy.sparse CSR matrix, a copy may still be
 |      returned.
 |  
 |  with_mean : bool, default=True
 |      If True, center the data before scaling.
 |      This does not work (and will raise an exception) when attempted on
 |      sparse matrices, because centering them entails building a dense
 |      matrix which in common use cases is likely to be too large to fit in
 |      memory.
 |  
 |  with_std : bool, default=True
 |      If True, scale the data to unit variance (or equivalently,
 |      unit standard deviation).
 |  
 |  Attributes
 |  ----------
 |  scale_ : ndarray of shape (n_features,) or None
 |      Per feature relative scaling of the data to achieve zero mean and unit
 |      variance. Generally this is calculated using `np.sqrt(var_)`. If a
 |      variance is zero, we can't achieve unit variance, and the data is left
 |      as-is, giving a scaling factor of 1. `scale_` is equal to `None`
 |      when `with_std=False`.
 |  
 |      .. versionadded:: 0.17
 |         *scale_*
 |  
 |  mean_ : ndarray of shape (n_features,) or None
 |      The mean value for each feature in the training set.
 |      Equal to ``None`` when ``with_mean=False``.
 |  
 |  var_ : ndarray of shape (n_features,) or None
 |      The variance for each feature in the training set. Used to compute
 |      `scale_`. Equal to ``None`` when ``with_std=False``.
 |  
 |  n_features_in_ : int
 |      Number of features seen during :term:`fit`.
 |  
 |      .. versionadded:: 0.24
 |  
 |  feature_names_in_ : ndarray of shape (`n_features_in_`,)
 |      Names of features seen during :term:`fit`. Defined only when `X`
 |      has feature names that are all strings.
 |  
 |      .. versionadded:: 1.0
 |  
 |  n_samples_seen_ : int or ndarray of shape (n_features,)
 |      The number of samples processed by the estimator for each feature.
 |      If there are no missing samples, the ``n_samples_seen`` will be an
 |      integer, otherwise it will be an array of dtype int. If
 |      `sample_weights` are used it will be a float (if no missing data)
 |      or an array of dtype float that sums the weights seen so far.
 |      Will be reset on new calls to fit, but increments across
 |      ``partial_fit`` calls.
 |  
 |  See Also
 |  --------
 |  scale : Equivalent function without the estimator API.
 |  
 |  :class:`~sklearn.decomposition.PCA` : Further removes the linear
 |      correlation across features with 'whiten=True'.
 |  
 |  Notes
 |  -----
 |  NaNs are treated as missing values: disregarded in fit, and maintained in
 |  transform.
 |  
 |  We use a biased estimator for the standard deviation, equivalent to
 |  `numpy.std(x, ddof=0)`. Note that the choice of `ddof` is unlikely to
 |  affect model performance.
 |  
 |  For a comparison of the different scalers, transformers, and normalizers,
 |  see :ref:`examples/preprocessing/plot_all_scaling.py
 |  <sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.
 |  
 |  Examples
 |  --------
 |  >>> from sklearn.preprocessing import StandardScaler
 |  >>> data = [[0, 0], [0, 0], [1, 1], [1, 1]]
 |  >>> scaler = StandardScaler()
 |  >>> print(scaler.fit(data))
 |  StandardScaler()
 |  >>> print(scaler.mean_)
 |  [0.5 0.5]
 |  >>> print(scaler.transform(data))
 |  [[-1. -1.]
 |   [-1. -1.]
 |   [ 1.  1.]
 |   [ 1.  1.]]
 |  >>> print(scaler.transform([[2, 2]]))
 |  [[3. 3.]]
 |  
 |  Method resolution order:
 |      StandardScaler
 |      sklearn.base._OneToOneFeatureMixin
 |      sklearn.base.TransformerMixin
 |      sklearn.base.BaseEstimator
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, *, copy=True, with_mean=True, with_std=True)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  fit(self, X, y=None, sample_weight=None)
 |      Compute the mean and std to be used for later scaling.
 |      
 |      Parameters
 |      ----------
 |      X : {array-like, sparse matrix} of shape (n_samples, n_features)
 |          The data used to compute the mean and standard deviation
 |          used for later scaling along the features axis.
 |      
 |      y : None
 |          Ignored.
 |      
 |      sample_weight : array-like of shape (n_samples,), default=None
 |          Individual weights for each sample.
 |      
 |          .. versionadded:: 0.24
 |             parameter *sample_weight* support to StandardScaler.
 |      
 |      Returns
 |      -------
 |      self : object
 |          Fitted scaler.
 |  
 |  inverse_transform(self, X, copy=None)
 |      Scale back the data to the original representation.
 |      
 |      Parameters
 |      ----------
 |      X : {array-like, sparse matrix} of shape (n_samples, n_features)
 |          The data used to scale along the features axis.
 |      copy : bool, default=None
 |          Copy the input X or not.
 |      
 |      Returns
 |      -------
 |      X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)
 |          Transformed array.
 |  
 |  partial_fit(self, X, y=None, sample_weight=None)
 |      Online computation of mean and std on X for later scaling.
 |      
 |      All of X is processed as a single batch. This is intended for cases
 |      when :meth:`fit` is not feasible due to very large number of
 |      `n_samples` or because X is read from a continuous stream.
 |      
 |      The algorithm for incremental mean and std is given in Equation 1.5a,b
 |      in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. "Algorithms
 |      for computing the sample variance: Analysis and recommendations."
 |      The American Statistician 37.3 (1983): 242-247:
 |      
 |      Parameters
 |      ----------
 |      X : {array-like, sparse matrix} of shape (n_samples, n_features)
 |          The data used to compute the mean and standard deviation
 |          used for later scaling along the features axis.
 |      
 |      y : None
 |          Ignored.
 |      
 |      sample_weight : array-like of shape (n_samples,), default=None
 |          Individual weights for each sample.
 |      
 |          .. versionadded:: 0.24
 |             parameter *sample_weight* support to StandardScaler.
 |      
 |      Returns
 |      -------
 |      self : object
 |          Fitted scaler.
 |  
 |  transform(self, X, copy=None)
 |      Perform standardization by centering and scaling.
 |      
 |      Parameters
 |      ----------
 |      X : {array-like, sparse matrix of shape (n_samples, n_features)
 |          The data used to scale along the features axis.
 |      copy : bool, default=None
 |          Copy the input X or not.
 |      
 |      Returns
 |      -------
 |      X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)
 |          Transformed array.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from sklearn.base._OneToOneFeatureMixin:
 |  
 |  get_feature_names_out(self, input_features=None)
 |      Get output feature names for transformation.
 |      
 |      Parameters
 |      ----------
 |      input_features : array-like of str or None, default=None
 |          Input features.
 |      
 |          - If `input_features` is `None`, then `feature_names_in_` is
 |            used as feature names in. If `feature_names_in_` is not defined,
 |            then names are generated: `[x0, x1, ..., x(n_features_in_)]`.
 |          - If `input_features` is an array-like, then `input_features` must
 |            match `feature_names_in_` if `feature_names_in_` is defined.
 |      
 |      Returns
 |      -------
 |      feature_names_out : ndarray of str objects
 |          Same as input features.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from sklearn.base._OneToOneFeatureMixin:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from sklearn.base.TransformerMixin:
 |  
 |  fit_transform(self, X, y=None, **fit_params)
 |      Fit to data, then transform it.
 |      
 |      Fits transformer to `X` and `y` with optional parameters `fit_params`
 |      and returns a transformed version of `X`.
 |      
 |      Parameters
 |      ----------
 |      X : array-like of shape (n_samples, n_features)
 |          Input samples.
 |      
 |      y :  array-like of shape (n_samples,) or (n_samples, n_outputs),                 default=None
 |          Target values (None for unsupervised transformations).
 |      
 |      **fit_params : dict
 |          Additional fit parameters.
 |      
 |      Returns
 |      -------
 |      X_new : ndarray array of shape (n_samples, n_features_new)
 |          Transformed array.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from sklearn.base.BaseEstimator:
 |  
 |  __getstate__(self)
 |  
 |  __repr__(self, N_CHAR_MAX=700)
 |      Return repr(self).
 |  
 |  __setstate__(self, state)
 |  
 |  get_params(self, deep=True)
 |      Get parameters for this estimator.
 |      
 |      Parameters
 |      ----------
 |      deep : bool, default=True
 |          If True, will return the parameters for this estimator and
 |          contained subobjects that are estimators.
 |      
 |      Returns
 |      -------
 |      params : dict
 |          Parameter names mapped to their values.
 |  
 |  set_params(self, **params)
 |      Set the parameters of this estimator.
 |      
 |      The method works on simple estimators as well as on nested objects
 |      (such as :class:`~sklearn.pipeline.Pipeline`). The latter have
 |      parameters of the form ``<component>__<parameter>`` so that it's
 |      possible to update each component of a nested object.
 |      
 |      Parameters
 |      ----------
 |      **params : dict
 |          Estimator parameters.
 |      
 |      Returns
 |      -------
 |      self : estimator instance
 |          Estimator instance.

The bad news is that working with scikit-learn takes some practice, partially because it is very object-oriented in its style. The good news is that the different tools from scikit-learn mostly work very similarly (they have a very similar syntax to each other).

Here we instantiate a StandardScaler object.

# exact same as `scaler = StandardScaler(with_std=False)`
scaler = StandardScaler(with_mean=True, with_std=False)
type(scaler)
sklearn.preprocessing._data.StandardScaler

Many of the objects we work with from scikit-learn have a fit method and either a predict method or a transform method. Here is an example of using the fit and transform methods of scaler.

scaler.fit(df[numcols])
StandardScaler(with_std=False)

This scaler has lots of different methods and attributes. (Typically you should ignore the ones that begin and end with double underscores. These are called “dunder” methods, and usually we do not use them directly.)

dir(scaler)
['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__setstate__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_check_feature_names',
 '_check_n_features',
 '_get_param_names',
 '_get_tags',
 '_more_tags',
 '_repr_html_',
 '_repr_html_inner',
 '_repr_mimebundle_',
 '_reset',
 '_validate_data',
 'copy',
 'feature_names_in_',
 'fit',
 'fit_transform',
 'get_feature_names_out',
 'get_params',
 'inverse_transform',
 'mean_',
 'n_features_in_',
 'n_samples_seen_',
 'partial_fit',
 'scale_',
 'set_params',
 'transform',
 'var_',
 'with_mean',
 'with_std']

Now that we have fit scaler, the mean_ attribute holds the mean values from the columns.

scaler.mean_
array([6.89996764e-01, 6.33495146e-01, 1.23655728e-01, 2.48694503e-01,
       5.14703819e-01, 1.97940817e+05])

Now we use the transform method.

df3[numcols] = scaler.transform(df[numcols])

Now the numeric columns of df3 all have means very close to zero.

df3[numcols].mean(axis=0)
Danceability    -8.738066e-17
Energy          -5.058880e-17
Speechiness      1.149746e-18
Acousticness     3.219287e-17
Valence          1.034771e-17
Duration (ms)   -6.630776e-12
dtype: float64
df2 == df3
Artist Song Name Week of Highest Charting Danceability Energy Speechiness Acousticness Valence Duration (ms)
0 True True True True True True True True True
1 True True True True True True True True True
2 True True True True True True True True True
3 True True True True True True True True True
4 True True True True True True True True True
... ... ... ... ... ... ... ... ... ...
1551 True True True True True True True True True
1552 True True True True True True True True True
1553 True True True True True True True True True
1554 True True True True True True True True True
1555 True True True True True True True True True

1545 rows × 9 columns

It looks like these values are all equal. Are they?

(df2 == df3).all()
Artist                      True
Song Name                   True
Week of Highest Charting    True
Danceability                True
Energy                      True
Speechiness                 True
Acousticness                True
Valence                     True
Duration (ms)               True
dtype: bool
(df2 == df3).all(axis=0)
Artist                      True
Song Name                   True
Week of Highest Charting    True
Danceability                True
Energy                      True
Speechiness                 True
Acousticness                True
Valence                     True
Duration (ms)               True
dtype: bool

Here we make a new StandardScaler object, this time using the default values, which indicate scaler2 should store both the mean and the std from the numeric columns.

# same as scaler2 = StandardScaler()
scaler2 = StandardScaler(with_mean=True, with_std=True)
scaler2.fit(df3[numcols])
StandardScaler()

Because scaler2 was fit using a DataFrame where the mean of the numeric columns was already (approximately) zero, the mean_ attribute of scaler2 will contain values close to 0.

scaler2.mean_
array([-8.73806601e-17, -5.05888032e-17,  1.14974553e-18,  3.21928748e-17,
        1.03477097e-17, -6.63077561e-12])