1

I feel like there is a simple solution to this but I am kinda new.

stat_input= input("Hello Mr. Jenner, what are you interested in tracking today?")

I use an input like this which later is used to call upon data and uses that data to calculate statistics and produce histogram charts / normal distributions.

It works quite nicely. Here are some examples where it is used.

cur.execute('SELECT {} FROM statdata'.format(stat_input))
np.array(stat_input).astype(np.float)

sigma = math.sqrt(np.var(stat_input))

So if I type threemonthdata it will pull the array of data from my database and use it . Its great. However, I have one small problem

I understand that threemonthdata refers to an array. Since I am creating charts, I want to use the input as the title so the chart title identifies what data I am drawing and using (as a reference in the future)

ax.set_title('stat_input')

This doesn't work

ax.set_title(' + stat_input + ') 

Nor does this. I want the title to say Threemonthdata. But if I input twomonthdata I want it to say twomonthdata and not give me the array of numbers.

Any ideas?

0

2 Answers 2

1

I have never played with psycopg's cursor class. But, from what I can read, it appears that this one does the job for you of turning your string in place into a list whose name is the same as the referring string.

Thus what about defining another viariable to store the string before it is overriden ? As follows

stat_input_title = stat_input.capitalize()
cur.execute('SELECT {} FROM statdata'.format(stat_input))

Henceforth, stat_input_title and stat_input can be used together withouh conflicting.

ax.set_title(stat_input_title)
Sign up to request clarification or add additional context in comments.

Comments

0

It looks like the issue you are facing is that you are passing the set_title() a string 'stat_input', and not the variable stat_input. You likely simply need to use:

ax.set_title(stat_input) 

1 Comment

You are right, but how could math.sqrt(np.var(stat_input)) works in this case ? stat_input is an array since the OP says : "I want the title [...] not give me the array of numbers." Also, it appears that the OP thinks that by doing 'stat_input', he will get as string the original name of the numpy array. Actually, as if he were coding in stata, handling local macros.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.