Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



Thanks for inadvertently bringing f-strings to my attention. I always use str.format() but that seems like a better way to do that...

Adbot
ADBOT LOVES YOU

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



What's the best way to go through a pandas dataframe and convert all of the values to a different value if they meet a set criteria? I've got a data frame representing grayscale images, where each cell is a value between 0 and 255, and I'd like to just convert this to black and white by changing anything that's not zero into a 1 prior to doing some analysis on it. Is this something I should use .apply for?

Forgive me if this is a stupid question, but I'm really new to working with pandas and its slightly different from how a lot of python base types work.

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



That... makes sense. I was overcomplicating this. It returns another df rather than changing it in place, right?

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



Pandas question! I've got a json file with stupid amounts of nesting that I want to turn into a nice flat datafile. Basically for each record I want to pull just a few features out of each property that are nested two and sometimes three layers deep rather than just flattening the whole thing out and ending up with a ton of extraneous columns.

My naive approach was to create an empty dataframe, iterate through the json file and grab things, stick those in a Series and then stick the Series in the dataframe, but I know this can't be the right way to do this. What should I be doing instead?

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



I'm going to be getting these json files in batches to process, 100 or so a batch, so I'd like to make this operation reasonably lightweight if I can, but it also doesn't need to be insanely optimized either. I'm okay with running it and then going to get lunch if need be. I think I'm going to basically follow Eela6's approach, make a list of Serieses, and then concatenate it into a DataFrame. That should be good enough. Thanks for your help!

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



That seems... not very pythonic?

Adbot
ADBOT LOVES YOU

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



I wouldn't use it preferentially over the JS IDE if I was doing pure JS but if you're doing a full stack project with Python you can do the frontend stuff in Pycharm and it's actually really seamless and nice.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply