ValueError: Value of 'x' is not the name of a column in 'data_frame' - python

I need help with my code, at first it run and showed results but second time of running it crashed and showed me an error, I tried everything to fix it but nothing. any help? would appreciate it.
figure = px.scatter(data_frame = data,
x="distance",
y="Time_taken(min)",
size="Time_taken(min)",
trendline="ols",
title = "Relationship Between Distance and Time Taken")
figure.show()
I tried everything to fix it, but nothing worked

Related

How to customize hover information depending on variable value

I have a dataframe with several columns. I'm interested in displaying some of this info when hovering over a specific point using plotly with python. I've discovered how to do this using customdata=dataframme[["A","B"]] being provided to my go.scatter.
Problem is that when I create hovertemplate, it could happen I don't want to display some info it that value is not available.
This is the code snippet :
fig.add_trace(
go.Scatter(x=df['Request time'], y=df['Taken time'], name="System performance", hovertemplate=
"<br>Request period: %{text}<br>" +
"Taken time: %{y}<br>" +
"Error msg: %{customdata[0]}<br>" +
"LogCorr: %{customdata[1]}<br>",
customdata=df[["ai","logCorr"]],
text=df['Request period']),
secondary_y=True,
)
This is working fine, but if I leave this like it is, when "ai" value is empty, I see quite ugly hover
I was thinking if there is some way to display hover info when column value exists (in my case) and display nothing when it doesn't
Something so "easy" like "" if X==0 else "Error message : %{customdata[1]} in hovertemplate.
This is not working due to customdata means nothing to python in execution time. I've tried for looking which language is used in hovertemplate but no luck
Thanks a lot for your help
Sure, #Phoenix, Thanks for your help
Result,Request period,Request time,Taken time,rc,ac,ai,logCorr,rcvTS,to
0,2022.09.21D15:50:06-2022.09.21D15:51:06,2022-09-21 15:54:28.620446,0:00:00.392736,0,0,,2f85cfdd-9539-49d7-83af-8df98619dd52,2022-09-21 15:54:28.939000,2022-09-21 15:54:58.939000
0,2022.09.21D15:51:10-2022.09.21D15:52:10,2022-09-21 15:54:29.367677,0:00:00.367510,0,0,,18e61236-3b70-46e9-8b0d-c1bdc7557ed8,2022-09-21 15:54:29.662000,2022-09-21 15:54:59.662000
0,2022.09.21D15:52:19-2022.09.21D15:53:19,2022-09-21 15:54:30.085704,0:00:00.357543,0,0,,7c3784fb-481b-432b-80d9-4c1654bcb565,2022-09-21 15:54:30.383000,2022-09-21 15:55:00.383000
0,2022.09.21D15:53:26-2022.09.21D15:54:26,2022-09-21 15:54:30.792658,0:00:00.375392,0,0,Time out,b52126a5-7c1b-4898-811d-65446fdda65d,2022-09-21 15:54:31.092000,2022-09-21 15:55:01.092000
In this example latest line contains timeout error and rest of lines do not contain any error. When I try to run this, Time out is properly displayed, problem is that when there is no ai, I see what you see in my screen shot.
When a column in csv does not have info, pandas is reading it as nan

Output not showing on Jupiter Lab for Python

After print command output is not showing. It happens few time back, after an hour same code runs smoothly. As I am a beginner I don't know much about what's happening.
first = 'dip'
last = 'rakshit'
print = (first, last)
Just remove the "="
first='dip'
last='rakshit'
print(first,last)

changing value in python

I'm scraping some info from a site using python and one of the value's has to be in the name of the file.
for this specific part I can't seem to get it to print right.
In the API there is a line like this:
BroadcastDate = 20100401
now I want to print this value like this.
01.04.2010
I know there is a lot possible in Python with text but I can't seem to figure it out or find anything on Google.
you smart guys probably know if its possible and how.
if something is unclear or you have a question, let me know!
EDIT
so I got the following piece of code which should need to work in my head but I dont get a response:
b = "20100104"
print((b[7:8]).(b[5:6]).(b[1:4]))
Thanks #Barmar your awnser put me in the right direction.
This worked:
b = "20100103"
year = (b[0:4])
month = (b[4:6])
day = (b[6:9])
print ((day) +(".") +(month) +(".") +(year))

Program doesn't append file using variables, but no error message appears

Using Python 3.4.2
I'm working on a quiz system using python. Though it hasn't been efficient, it has been working till now.
Currently, I have a certain user log in, take a quiz, and the results of the quiz get saved to a file for that users results. I tried adding in so that it also saves to a file specific to the subject being tested, but that's where the problem appears.
user_score = str(user_score)
user_score_percentage_str = str(user_score_percentage)
q = open('user '+(username)+' results.txt','a')
q.write(test_choice)
q.write('\n')
q.write(user_score+'/5')
q.write('\n')
q.write(user_score_percentage_str)
q.write('\n')
q.write(user_grade)
q.write('\n')
q.close()
fgh = open(test_choice+'results.txt' ,'a')
fgh.write(username)
fgh.write('\n')
fgh.write(user_score_percentage_str)
fgh.write('\n')
fgh.close
print("Your result is: ", user_score , "which is ", user_score_percentage,"%")
print("Meaning your grade is: ", user_grade)
Start()
Everything for q works (this saves to the results of the user)
However, once it comes to the fgh, the thing doesn't work at all. I receive no error message, however when I go the file, nothing ever appears.
The variables used in the fgh section:
test_choice this should work, since it worked for the q section
username, this should also work since it worked for the q section
user_score_percentage_str and this, once more, should work since it worked for the q section.
I receive no errors, and the code itself doesn't break as it then correctly goes on to print out the last lines and return to Start().
What I would have expected in the file is to be something like:
TestUsername123
80
But instead, the file in question remains blank, leading me to believe there must be something I'm missing regarding working the file.
(Note, I know this code is unefficient, but except this one part it all worked.)
Also, apologies if there's problem with my question layout, it's my first time asking a question.
And as MooingRawr kindly pointed out, it was indeed me being blind.
I forgot the () after the fgh.close.
Problem solved.

Simple split string not working in zapier

I'm using zapier to put different apps together. I need to split a string custom_id that has 6 parts that are separated by an underscore. For example, sk000_i093_14.50_5_MNE_2017-07-25
Here's my code:
split_str = input_data['custom_id'].split("_")
output = [{'sk':split_str[0], 'buy_invoice':split_str[1], 'sales_amt':split_str[2], 'UPI':split_str[3], 'buyer':split_str[4], 'date_buy':split_str[5]}]
I also tried it this way:
sk, buy_invoice, sales_amt, upi, buyer, date_buy = input_data['custom_id'].split("_")
output = [{'sk':sk, 'buy_invoice':buy_invoice, 'sales_amt':sales_amt, 'upi':upi, 'buyer':buyer, 'date_buy':date_buy}]
I've searched and searched and haven't found anything specific to zapier on why my simple split string isn't working with zapier. When I test the code zapier doesn't give a useful error message, just:
"Bargle. We hit an error creating a run python. Error: Your code had
an error!"
I've tried running it multiple ways, but whenever I try to retrieve the data from the split I get the very unhelpful error message.
Any help is very much appreciated! Thanks!
UPDATE:
When you go to test the code, Zapier shows test data for input_data. Even though this data is showing up correctly, during the actual test run input_data is empty! So there was nothing wrong with the split. Phew!
Thanks!
The split was correct. The problem was input_data wasn't being populated, even though Zapier showed the correct data was going to populate it, input_data was empty anyway. I added some more key:value pairs to input_data because I needed them, refreshed the webpage, refreshed the fields, and re-tested the code, and input_data finally got populated and the code ran perfectly.
Thanks to PRMoureu and E. Ducateme for giving me the idea to check my input_data (Duh!).

Categories

Resources