Home > Software design >  How to convert from pandas Series to an int
How to convert from pandas Series to an int

Time:07-19

I'm trying to convert times from UTC to local times for various countries.

To do this I'm searching a dataframe for the country name to find the timezone

if (country == "Brazil" or country == "DR-Congo" or country == "Indonesia" or country == "Kazakhstan" or country == "Russia"):
            tz = files.tz_club.loc[files.tz_club["shrt_nme"] == teamname, "summer"]

In this instance I am looking up a timezone for Brazil and tz prints as:

215   -3
Name: summer, dtype: int32

But when I try running it through a timedelta adjust_time = timedelta(hours = tz) I'm met with the following error: TypeError: unsupported type for timedelta hours component: Series

I've tried to convert it to int using tz = tz.astype(int), but that doesn't affect anything.

Could someone point me in the right direction, please? TIA.

Edit: Here is an example of what tz_club looks like...

                     team  winter  summer country        shrt_nme      á      é      í      ó      ú      ñ  count
0  Atlético de Alagoinhas      -3      -3  Brazil  Atlético de Al  False   True  False  False  False  False      1
1             Atletico GO      -3      -3  Brazil     Atletico GO  False  False  False  False  False  False      0
2             Atletico MG      -3      -3  Brazil     Atletico MG  False  False  False  False  False  False      0

CodePudding user response:

As stated by @JNevill in a comment, I needed to convert the Series inside of the timedelta itself rather than before it.

timedelta(hours = int(tz)) works great.

  • Related