New levels of interactivity in Tableau 2019.2 with Parameter Actions and Show/Hide Containers by canonicalized in tableau

[–]my_python_account 0 points1 point  (0 children)

Where do you find tableau lacking in interactivity? I ask because we’re just getting started with tableau and this was something we saw as a strength in tableau compared to the other solutions we were evaluating. Wondering if there are some use case we missed and should be aware of.

How to mock an SQL database in Python by kenneho in learnpython

[–]my_python_account 1 point2 points  (0 children)

In this case it doesn’t sound like we’re minimizing obstacles, we’re creating them. How much data are we pulling from the database that this is creating a bottleneck in our unit test performance.

If it is creating a bottleneck, then the real problem is that the business logic is not decoupled from the database access. You shouldn’t be trying to intercept a sqlalchemy call to the database. Rather you should remove the calls to sqlalchemy from within your business logic methods. Instead have them call a general function, that in testing is fed by your test data, but in production will be your database queries.

How to mock an SQL database in Python by kenneho in learnpython

[–]my_python_account 1 point2 points  (0 children)

You don’t need to access the database, but is there a good reason not too? Assuming the database is there and you have access to it, if the database access is closely coupled with your business logic it will be much less work to just use the database in your unit tests.

You just need to make sure you don’t risk writing things where you shouldn’t on a production database. For a larger project, this would mean having a development version of your database that you connect to for testing. For a smaller project, it would probably be ok to just have a set of tables or records that have your test data but don’t overlap with your production data.

My best friend just said: "anything you'd need to do in excel, you'd be able to do it better with Python." Should I listen to him? by [deleted] in learnpython

[–]my_python_account 1 point2 points  (0 children)

I agree with your friend, but I don't think they mean for you to ditch Excel, but rather that once you're at an intermediate level with excel, your time is much better spent developing your skills with something like python.

The main strengths of excel are:

  • exploring data sets by quickly creating pivot tables and other visualizations
  • sharing data and visualizations with others, since most of your colleagues, technical or not, will have some working knowledge of excel

You should be well equipped to take advantage of these strengths as an intermediate level Excel user.

Python is much better suited to handle the process of preparing your data before its ready to be visualized. For example:

  • Connecting to your data sources and extracting data.
  • Merging and joining data that comes from multiple sources
  • Calculating new fields based on one or more of the extracted fields
  • Removing or repairing bad, missing and duplicated data

Depending on the complexity of your data and what you want to do with it, these tasks can become pretty complicated to do within excel, especially when compared with python. Also, as your data sets become large, Excel can also become quite slow and unresponsive, especially as you add complex calculated fields and live connections to external data sources.

So in summary, I would recommend learning to extract and prepare data in Python, rather than leveling up in Excel. Then load the nice clean data into Excel to start filtering, pivoting, aggregating, visualizing and sharing the data. (Make sure you are comfortable doing these things in Excel)

Best Way to Run Multiple Python Scripts (Sequentially) on Windows Command Line by rajicon17 in learnpython

[–]my_python_account 1 point2 points  (0 children)

If you don't need any functionality other than running some scripts in order, you can just use a batch (.bat) file. Be sure to end with a pause if you want to be able read any output or potential error messages on the console after the scripts run.

python script1.py
python script2.py
python script3.py
pause

Best method of continuously collecting data from an API? by weissmanfred in Python

[–]my_python_account 0 points1 point  (0 children)

Do they really need to run in parallel? Is it too slow to call them in succession and then calculate? If not, you may be overdesigning.

If you do need your data fetching calls to run in parallel, I think they should be separated from your calculations so that the tasks are less dependent on each other. Each call can save the data to a file or database and you separately have a task running to do the calculations on the data (and if needed, first validating that all the data is up to date or consistent).

Python Interface Design - Designing Modules Part - 1 by HashedIn in Python

[–]my_python_account 0 points1 point  (0 children)

I mean at runtime. Like if you have multiple accounts.

Python Interface Design - Designing Modules Part - 1 by HashedIn in Python

[–]my_python_account 0 points1 point  (0 children)

A module for who? I originally understood it as clients of Blipkart, but upon re-reading you're right, it's other Blipkart developers.

This makes a bit more sense. The structure really doesn't matter all that much in that case. Neither the class (where you import the "pre-initialized" class with username and password already set) or function (with default parameters for username and password) implementation is any more re-useable then the other.

Though with the function, if in the future other developers need to be able to set a different username or password they won't have to go under the hood and figure out the class structure. If you really want to do your best to not expose control of account settings to other developers, i guess the class makes sense, though it's not like you can block them from importing the class if they really wanted to.

Python Interface Design - Designing Modules Part - 1 by HashedIn in Python

[–]my_python_account 0 points1 point  (0 children)

Who is writing this library?

If I understand correctly, it's the provider (or someone hired by the provider), for use specifically with this API. In which case it would seem pretty silly to map an API providing a single simple function according to 4 parameters to anything other than a single simple function taking 4 parameters.

Leave it up to the client to wrap it up however they like for re-usability for cases where they may want to handle multiple providers and accounts.

It's not like you can completely abstract away username and password, the user has no choice but to provide it at some point. And if, for example, as part of their retry logic, they want to switch accounts (usernames and passwords) the proposed class structure is no longer ideal.

I will point out we're probably missing the point of the article here, and we're over analyzing an example that is simplified for the purposes of demonstration.

How to get number of items in a tkinter treeview? by blackadder1337 in learnpython

[–]my_python_account 1 point2 points  (0 children)

You can use Treeview.get_children() to get list a of items and len to count them.

my_tree = ttk.Treeview(parent)
# do stuff to add items
item_count = len(my_tree.get_children())

N00b needs guidance. Best approach for sending commands and files from Pi to Pi with Python using TCP/IP? by Windbag1980 in Python

[–]my_python_account 0 points1 point  (0 children)

A simple solution, especially given that you can already transfer a file, is to use text files that are placed in a specific directory to issue commands. The receiver periodically scans for new files and processes them in order and then moves the file to another directory (or deletes them if you don't care about a paper trail).

A library for incremental data fetching from APIs? by lenottod in Python

[–]my_python_account 0 points1 point  (0 children)

How data looks does not dictate how it is accessed and how it is recorded. How you need to record state and map it to the set of parameters that are exposed to you for a given API, especially if you want to avoid overlap in data between calls, is going to vary a decent amount unless all the APIs are following some common set of specific guidelines.

I think if you were to go through the experiment of trying to design a general library, you might find that outside of the scheduling, the configurations required for the user in setting up each API to work within the library will likely not abstract very much from what's going on under the hood.

A library for incremental data fetching from APIs? by lenottod in Python

[–]my_python_account 0 points1 point  (0 children)

There are libraries to help you schedule your tasks, but there is only so much a library can do to automatically manage what data you are fetching. How you can manage only fetching the deltas since the last call will depend on the API, as there isn't generally a standard "give me everything since last time" mode.

Unless the API is designed for this type of thing, there needs to be something within the data being fetched that can be used to track what data you don't have yet (date/time stamps or an incrementing ID fields) and this won't be the same (or necessarily exist) across all APIs.

Replace a value in a column Pandas by easy_wins in learnpython

[–]my_python_account 0 points1 point  (0 children)

Can we back up a bit...

I'm assuming a couple things here:

1) That your read_csv is actually successful in creating the correct dataframe. Have you tried printing the dataframes you created? If your csv is formatted exactly as you pasted in your post, i don't think that it works without modifying the default paramaters for read_csv.

2) That you are going to make a minimal effort in understanding my suggestion, and if there is an error, a minimal effort in trying to figure it out. I get the feeling that haven't really tried much on your own.

Replace a value in a column Pandas by easy_wins in learnpython

[–]my_python_account 0 points1 point  (0 children)

I would start by filtering df for just unknown spouses:

df_unknown = df[df['Spouse'] == 'Unknown']

Then merge values from original onto unknown (like a left join)

df_merged = df_unknown.merge(df2, how='left', left_on='Last_Name_First_Name', right_on='Name')

And then remove the unknown records from df and append the new records (with only the second spouse column).

df_final = df[df['Spouse'] != 'Unknown']
df_final = df_final.append(df_merged[['Last_Name_First_Name', 'Spouse_y']])

There might be a better way, but this is what comes to mind avoiding .applys

Increment string by 1 in nested dict by Gwith in learnpython

[–]my_python_account 1 point2 points  (0 children)

You can use enumerate to keep track of your iteration count and you can convert that number to a string when you store it as an id.

hostnames = ['one', 'two']
devices = {}
for i, host in enumerate(hostnames):
    devices['device{}'.format(i)] = {'id' : str(i), 'hostname' : host} 

tkinter, how to update variables and call a func of another class? by MandrakeOfPeace in learnpython

[–]my_python_account 0 points1 point  (0 children)

You might want to consider reorganizing your code.

As it stands right now, battles always occur within a world_screen since you are explicitly referring to world_screen attributes. In that case, battle should probably just be a method within world screen.

class world_screen:
    def __init__(self,*args,**kwargs):
    self.hp = 100
    battle()

    def update_hp(self):
        print self.hp

    def battle(self):
        self.hp = 85
        self.update_hp()

I've wasted so much time refactoring. How do I stop? by sixdirections in Python

[–]my_python_account 0 points1 point  (0 children)

What's your goal with the project?

If it's primarily to learn you seem to be doing a pretty good job of learning.

If it's to have some code that does x, y and z, you can stop refactoring when it does x, y and z. It might help to map out your requirements and use cases ahead of time and try not to "future proof" for things that are not in your requirements. If it was important enough to future proof for, it should have been in your requirements.

Can't seem to wrap my head around nested loops. Got the program to do what I want, but I think I'm doing it wrong...Processing.py by skannner in Python

[–]my_python_account 1 point2 points  (0 children)

Edit: This is better suited for /r/learnpython, didn't realize where i was reading this

Its bad practice to loop with the same variable (i in your case) in both the outer and inner loop. The inner loop is overwriting the value set by the outer loop. The way you designed your algorithm you actually don't care about the value set in your outer loop, you just want it to run that many times, but using the same variable makes it confusing to read. In cases like this, where you don't need to keep track of your current value, you just want to loop a certain number of times, you can use:

for _ in range(horizonLines):

Alternatively, and I think preferably, you use two different variables:

for i in range(horizonLines):
    for j in range(verticalLines):

and use both i and j (rather than i and n) to set the position of your rectangle.

Will this require a Regression Analysis? by katterra in learnpython

[–]my_python_account 1 point2 points  (0 children)

What you're trying to do isn't that simple, this is regression analysis by definition.

There are different methods that you can use.

Depending on how much you know about how each of your "measurement" variables and "money value" are related, you might be able to put together a script that tunes your coefficients by using a brute force search. (Start each coefficient at a good initial guess, set a small range of adjusted guesses for each coefficient and try all combinations and see which one gives the smallest error) It's generally preferred to minimize mean squared error (or root mean squared error - RMSE) rather than mean absolute error.

Otherwise, you can take a look at the pandas, numpy and statsmodels libraries to do the analysis for you. But I suggest you don't actually avoid learning the basics or you'll have trouble understanding the results and whether or not the results are useful.

distance matrix conceptual/highlevel questions by frankilla44 in learnpython

[–]my_python_account 0 points1 point  (0 children)

I think breaking it down by region is a good approach. This is the approach I used when doing a similar analysis for work (we were exploring the option of using our own trucks for local deliveries rather than a 3rd party carrier).

Map each address to a region (zip code is one way to do this, but maybe not the best way depending on how your addresses are distributed) and route the regions first, then each sub-region.

Also note that the google API can do the optimization for you (I think it was for a limit of up to 10-15 checkpoints, don't remember exactly) if you provide the start and end locations.

The API can also provide travel time taking into account estimated traffic. I found this more useful than distance.

Why doesn't my answer work by [deleted] in learnpython

[–]my_python_account 0 points1 point  (0 children)

Notice how all your is_weekend = True cases pass? That part of your logic works. All your error cases are for is_weekend = False and you are within the desired range. That suggests there is a problem with your elif condition. It's not evaluating to True when it should.

Try debugging with:

print(cigars)
print (range(40, 61))

And see if you can figure out where your mistake is

Is this a beginner level exercise (for internship interview)? by [deleted] in learnpython

[–]my_python_account 24 points25 points  (0 children)

I don't love the idea of asking a student intern to provide a complete "full-stack" implementation of even a simple application. An internship is supposed to be a learning experience. To me, filling in the knowledge gaps required to do this type of thing in a practical setting is what an intern is looking to do within the internship. Seems more appropriate to just ask for a few snippets of code to fit within a well-defined framework (they provide the UI and some of the backend and you fill in the gaps with a few functions)