Cannot use f-string for equivalent operator

Asked 2 years ago, Updated 2 years ago, 16 views

I can't put the actual data on it for some reason, so please let me explain it with temporary data.

For example, suppose you read csv with column data such as temperature (°C), precipitation (mm/h), and county name and set it to df.

df=pd.read_csv('sample.csv', encoding='SHIFT-JIS')

Therefore, I wanted to take out the row data of 10 (*meaning 10mm/h) from the column of precipitation (mm/h), so

data=df[df['precipitation (mm/h)']==10]

said he.In fact, I was able to confirm that I could retrieve the data, so I decided to use the input function to determine how many mm/h rows of data to retrieve the data.
Here's the code you created.

RAIN=input('Please enter the amount of precipitation you want to obtain')
df=pd.read_csv('sample.csv', encoding='SHIFT-JIS')
data=df[df['Drainfall (mm/h)']==f'{RAIN}']

When I tried entering 10 in RAIN, there was no data for some reason.

I understand that f-string is probably not compatible with equivalent operators, but I couldn't find a way to deal with it when I searched python equivalent operator f-string etc.How can I improve it?

python

2022-09-30 16:59

1 Answers

As you can see in the comment, it was solved by changing the dtype.
Thank you for your reply.


2022-09-30 16:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.