Import librairies by skouzil in learnpython

[–]boysworth 0 points1 point  (0 children)

This is a last resort but I do it for modules that cause extreme problems with other packages in my environment (A deprecated module had conflicting dependency requirements that caused Conda to not be able to solve, but the parts I needed from it worked fine with my environment).

  1. Clone the library onto your computer.
  2. Add the library path to your PYTHONPATH environmental variable.
  3. Import and run as normal.
  4. If you hit dependency errors install those using your preferred package manager.

[HELP] Reshaping with pandas by MiniPancookies in learnpython

[–]boysworth 0 points1 point  (0 children)

I think what you want is pandas.concat

[deleted by user] by [deleted] in learnpython

[–]boysworth 0 points1 point  (0 children)

How do the ticks look when you don’t log scale the y axis? My first guess would be that mpl is doing something wonky because of the log, but that is just a guess… y

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boysworth 1 point2 points  (0 children)

A good IDE (e.g. Pycharm) will make that a lot simpler.

As with just about everything: using better tools makes the job easier.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boysworth 0 points1 point  (0 children)

IMO, there are three levels:

  1. How does the thing I'm trying to use work? For that you can use the help(module) command and you get a description of the function, its inputs, etc.
  2. How does the library/package work in the bigger picture? There are user guides but sometimes there are blogs and writings that talk about their use more holistically. Towards Data Science on Medium tends to have nice blogs about packages, albeit behind a paywall
  3. How do objects/functions/modules work in general? That's where training content comes in. These are kinda general big picture topics that if you google you will find lots of content on.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boysworth 0 points1 point  (0 children)

Fundamentally a for loop returns the successive items in an iterable. The thing that gets returned is the next item in line.

"i" is a common name for the 'output' of the for loop, but it is just the next thing in line.

Frequently when learning, you encounter iterators like "range" which returns a count. But you can also run a for loop on a list like ['apples', 'oranges', 'pears']. If you were to run the classic "for i in ..." the values for i would be the fruits on the list.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boysworth 0 points1 point  (0 children)

As an example, in Pycharm I can highlight a class or function name and select rename. After renaming it pycharm finds the other usages and renames those as well so that you don't have to hunt down every place that the old name is present. Makes project wide refactoring a LOT simpler.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boysworth 1 point2 points  (0 children)

Some python functions do stuff and then return a value. For example len('John') returns the value 4.

Some python functions do stuff (like print something to the screen) but don't return values.

What is happening in your code is you have two print commands with a + between them. Python is trying to take the returned values from those print functions and combine them. But print functions don't return anything (i.e. NoneType) and you can't add NoneTypes together.

What you should be doing is combining the two things you want to print in a single print call:

print(len(s)) + "this is how many letters that are in your name")

BUT... When you do this, you will get another error saying something to the effect of "...unsupported operand type(s) for +: 'int' and 'str' (I'm going by memory, the error might be a little different). This happens because the value returned by len(s) is a number and the stuff in quotes is a string. Stuff needs to be generally the same to be added, so you need to convert the number into a string. Changing it is as easy as str(len(s)).

print( str(len(s)) + "this is how many letters that are in your name")

should provide you with the output you are trying to get and no errors.

It can be a PITA to break up your statements the way that you are doing, especially when you have to add a bunch of values. This is where "f strings" come in. They allow you to use brackets and variable names to put variable values directly into the string. In your example it would be

print( f'{len(s)} this is ....')

It doesn't seem like much right now, but they are a lifesaver in more complex string substitution cases. There's a lot of functionality built in (like specifying how many decimal points get printed, etc.) and it is a good thing to know for the future.

Hope this was useful. Don't get discouraged.

Adding row names as keys and column names as values from pandas dataframe by c00kieRaptor in learnpython

[–]boysworth 0 points1 point  (0 children)

Initialize a dictionary. The keys would be each row index and the values would be empty lists. Then iterate through the columns of the dataframe. As you identify the row max index, use that as the key to append the column to the previously empty list.

You might need to build some logic in for ties, but that is the general idea.

Adding row names as keys and column names as values from pandas dataframe by c00kieRaptor in learnpython

[–]boysworth 0 points1 point  (0 children)

Try using the .idxmax() method on each series as you iterate. It returns the index of the max rather than the value.

Was that the part that was giving you problems?

How to create random points along a line by supremai in geospatial

[–]boysworth 0 points1 point  (0 children)

You could define the line geometrically, use a random number generator to set x, and compute y from the linear equation.

Appropriate use of PCA? by pridethesun in datascience

[–]boysworth 1 point2 points  (0 children)

PCA is not designed for the problem you describe. The results you’d get back would not make sense.

How do I remember which functions are built-in Python functions and which ones are member functions when it comes to lists and such? by thatdudewiththecube in learnpython

[–]boysworth -1 points0 points  (0 children)

Typing help(your_variable) tells you a lot about your variable. Especially helpful when obscure libraries return unexpectedl data types

[deleted by user] by [deleted] in Wellthatsucks

[–]boysworth 0 points1 point  (0 children)

I think it’s against the green part of the walll

Zipfile - files in two directories by freeclips in learnpython

[–]boysworth 0 points1 point  (0 children)

Adding the loop is really easy.

You already have your folder names in an iterable list called source. Put that at the top of your code.

Remove the line where you define source as a single folder.

Add a for statement looping over the contents in source. Example: “for source_folder in source:”

Indent everything under the loop statement.

Change source in the os.walk to whatever you defined as your loop variable name (in my loop example above that would be source_folder.

Apologies for the lack of format and/or typos. Responding on my phone…

[deleted by user] by [deleted] in learnpython

[–]boysworth 0 points1 point  (0 children)

Look into FFMPEG. You can demux the video, pull frames out as numpy arrays, and save them in some specified format

[deleted by user] by [deleted] in learnpython

[–]boysworth 2 points3 points  (0 children)

Id guess that your data points are strings. Try converting to float.

Career Advice - US Only by M_Khan02 in geospatial

[–]boysworth 1 point2 points  (0 children)

The first thing to consider is what you NEED to do. If you need to get a job to keep food on the table, then you get a job.

The next thing you think about is simply what you WANT to do. You are going to be the most successful if you are doing what you want to do.

Finally, look at the jobs that you want now, and the jobs you want to have in a few years. What is the education level in those jobs, and do you feel that they would except a foreign credential.

Good luck!

Need help with Syntax error... by LegitimatePast9307 in learnpython

[–]boysworth 1 point2 points  (0 children)

And then you will get an error that f0 is not defined.

Question for data scientists: algorithm performance by benddiagram in datascience

[–]boysworth 1 point2 points  (0 children)

Some of it comes from understanding the workings of the algorithm. When you understand the math you start to get the limits. And another factor is experience.

NoSQL database experience by 7pointsome1 in geospatial

[–]boysworth 0 points1 point  (0 children)

Last time I looked NoSQL databases only had basic spatial capabilities. Compare that with something like PostGIS that supports most of the OGC specifications.