#๐Ÿ”’ Python help

80 messages ยท Page 1 of 1 (latest)

oblique crest
#

Not sure how to fix this and generate a list. I'm supposed to get a list of 2 but im generating 0 anyone know whats wrong with my code?

hot pewterBOT
#

@oblique crest

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

oblique crest
#

plant_50614_generators = []

for idx in range(num_rows):
plant_id = cell(idx, 'plant_id')
technology = cell(idx, 'technology')
generator_id = cell(idx, 'generator_id')

# Check if plant_id is 50614 and technology is "Wood/Wood Waste Biomass"
if plant_id == "50614" and technology.lower() == "Wood/Wood Waste Biomass":
    plant_50614_generators.append(generator_id)

plant_50614_generators = sorted(plant_50614_generators, reverse=True)

Display the result

plant_50614_generators

hot pewterBOT
#

Hey @oblique crest!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
past crescent
#

You're not printing anything out.

woeful mirage
#

iirc jupyter notbook lets you just say the variable name to print in the console

oblique crest
#

What does that mean

#

What's wrong with the code

oblique crest
#

So what should I do

woeful mirage
#

you are doing .lower() but your string to compare isnt lowered

past crescent
#

@oblique crest What's in technology?

woeful mirage
oblique crest
#

Ohh

woeful mirage
#

Wood/Wood... should be wood/wood...

past crescent
#

That will never be true

oblique crest
#

i just changed it and it still didnt work :((

woeful mirage
#

also why is plant_id a string?

#

shouldnt it be a number

#

yeah

oblique crest
#

im using pre defined

#

functions

woeful mirage
#

try to remove the "" from the plant_id == ...

oblique crest
#

def cell(row_idx, col_name):
col_idx = csv_header.index(col_name)
val = csv_rows[row_idx][col_idx]
if val == " ":
return None

int_columns = ['entity_id', 'plant_id']
float_columns = ['net_summer_capacity', 'net_winter_capacity', 'latitude', 'longitude']
if col_name in int_columns:
    return int(val)
elif col_name in float_columns:
    return float(val)
else:
    return val
#

remove the quotations?

woeful mirage
#

yeah

#

since that cell function returns a int(val) if is a entity_id or plant_id

oblique crest
#

because for my project right here i have to use quotations

#

but idk too

woeful mirage
#

can you do a print(plant_id, technology)?

#

in the middle of for loop

oblique crest
#

ok

#

It prints out a very long list of the data im workin with

woeful mirage
#

could u show it

oblique crest
#

and it goes on and on

woeful mirage
#

wait

#

print(type(plant_id))

oblique crest
#

no it's not an int

#

i can show u the whole data set

#

ok

woeful mirage
#

int :3

#

remove the quotes from the if

oblique crest
#

ok

#

but my other ones

#

have the quotes

#

see like my definition here it uses a quotation around the entity name

woeful mirage
#
plant_50614_generators = []

for idx in range(num_rows):
    plant_id = cell(idx, 'plant_id')
    technology = cell(idx, 'technology')
    generator_id = cell(idx, 'generator_id')

    # Check if plant_id is 50614 and technology is "Wood/Wood Waste Biomass"
    if plant_id == 50614 and technology.lower() == "wood/wood waste biomass":
        plant_50614_generators.append(generator_id)

plant_50614_generators = sorted(plant_50614_generators, reverse=True)

# Display the result
plant_50614_generators
oblique crest
#

Lmaooooo

woeful mirage
#

try to run this

oblique crest
#

WAIT

#

IT WORKED LOL

#

Can u explain to me

woeful mirage
#

you are maybe confused about the primitive types of python

number = 50614 # this is a int
another_number = 12.34 # this is a float
text = "this is a string" # string
oblique crest
#

whatd u do ahaha

woeful mirage
#

as u saw the plant_id is a class 'int'

#

so its a number

oblique crest
#

yes i see that

#

Why do I put "" around it then

#

If it's a int

woeful mirage
#

you shouldn't

#

thats why wasnt working

oblique crest
#

Ohhhhh that makes sense now

#

I was confused with why it was like that

woeful mirage
#

so you was basicly trying to do:

if 50640 == "50640" ...:`
# number // string (text)
#

this would never be true

oblique crest
#

Hmmm ok ok that made sense

#

Can you also look at my other function right here too?

#

for idx in range(num_rows):
    plant_id = cell(idx, 'plant_id')
    technology = cell(idx, 'technology')
    net_summer_capacity = cell(idx, 'net_summer_capacity')

    if net_summer_capacity == "" or float(net_summer_capacity) <= 5:
        continue

    if technology.lower() == "conventional hydroelectric":
        powerful_hydro_electric_plants.append()

powerful_hydro_electric_plants = sorted(list(set(powerful_hydro_electric_plants)))

powerful_hydro_electric_plants ```
#

Idk what to put inside my powerful_hydro_electric_plants.append()

#

@woeful mirage

woeful mirage
oblique crest
hot pewterBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.