Python Forum
[pandas] convert Int to str
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pandas] convert Int to str
#8
I think you are correct.

Basically I am trying to sum up imports when Hs_code starts with 08.

data.loc[data.Hs_code.str[:2] == '08'].Imports_vfd.sum()
This code
data['Hs_code'] = f"{data['Hs_code']}"
converted it to a string but put an array of numbers in each input.

Does anyone know how I can do a slice on the first two digits of the int column (HS_code) and if those first two number = 02 then sum up imports_vfd.

Thanks for any help

Thanks scidam - your one worked. You'd think this would be a common issue and you could find the answer online easier :'(
Reply


Messages In This Thread
[pandas] convert Int to str - by Scott - Jun-21-2019, 10:20 PM
RE: convert Int to str - by Larz60+ - Jun-22-2019, 02:50 AM
RE: convert Int to str - by ThomasL - Jun-22-2019, 07:21 AM
RE: [pandas] convert Int to str - by Scott - Jun-22-2019, 08:10 PM
RE: [pandas] convert Int to str - by Larz60+ - Jun-23-2019, 09:04 AM
RE: [pandas] convert Int to str - by scidam - Jun-23-2019, 11:09 AM
RE: [pandas] convert Int to str - by ichabod801 - Jun-23-2019, 11:28 AM
RE: [pandas] convert Int to str - by Scott - Jun-24-2019, 07:05 AM
RE: [pandas] convert Int to str - by scidam - Jun-24-2019, 11:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pandas] Convert categorical data to numbers pradeep_as400 1 2,680 Jun-15-2019, 08:27 AM
Last Post: ThomasL
  Python read Password protected excel and convert to Pandas DataFrame FORTITUDE 2 17,156 Aug-30-2018, 01:08 PM
Last Post: FORTITUDE
  Convert indexing For Loop from MATLAB (uses numpy and pandas) bentaz 3 4,214 Mar-20-2018, 08:29 PM
Last Post: bentaz
  pandas convert date/time to week okl 3 6,711 Mar-03-2018, 10:15 PM
Last Post: marsokod
  How do I convert my data so it works with Pandas? Oliver 0 2,421 Dec-11-2017, 04:09 PM
Last Post: Oliver

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020