I am trying to plot ship trajectories in Cartopy, but am unable to automatically use a column of my df to set the color groups of the data. This throws the error ‘dtype: object is not a valid value for color’. In Geopandas you can set the color groups using the ‘column’ field. Is there…
datetime.combine with timezone is different from datetime.now with timezone
In the below code: Why are d1 and d2 showing different timezone information? How do I get the same datetime as datetime.now when using datetime.combine? Answer datetime.now effectively converts (localizes) your datetime with the pytz timezone object – from the docs: If tz is not None, it must be an inst…
python transform 1d array of probabilities to 2d array
I have an array of probabilities: and I want to make it 2d array: What is the best way to do so? Answer One idea is use numpy.hstack: Or use numpy.c_:
How to replace the ‘,’ between two numbers like X,X% into X.X% in all the dataframe python
I have a column in pandas data frame like below. Column name is ‘ingredients_text’ Now I want to replace all the values like 5,5% to 5.5% in this column in all the dataframe. Answer We can use str.replace here: The pattern b(d+),(d+)% matches in the first and second capture groups, respectively, t…
convert date month year time to date format pyspark
I have a file with timestamp column. When I try to read the file with a schema designed by myself it is populating the datetime column with null. Source file has data as below where I am using the below code snippet in the above DF.display() is showing the result as null for all the inputs. However my expecte…
How to split with Dot without splitting links [duplicate]
This question already has answers here: How to split by comma and strip white spaces in Python? (10 answers) Closed 1 year ago. I want to split on dot (.) but I don’t want to splits the links. Let’s say the string is – Expected Output – Current Output – Note that I don’t wa…
Python For Loop Count and Insert Numbers beside words
I have a problem regarding Python, I want to count the list item and then put a number beside the value of text. This is the output I want: This is the output I always get: Here is my line of code: Answer Fix You don’t need 2 loops, just iterate over text2 and increment your xn then append to
How to Subtract rows after group by in Python?
I had a dataframe and after applying groupby().sum, I got this outcome. What I have What I want now Things to consider B should remove from the dataframe because 100.00 – 100.00 = 0 Always Buy Amount > Sell Amount How can I achieve this result? Answer I guess it is not optimized way, but you can try …
How do I get multiple rows from django database?
Hello I am trying to create an employee attendance program and I want to make it so that the employees can see the total hours they worked. This is the code that creating the problem: The error I get is and if I use it shows an error that says Answer You must use filter and iterate over results as
Find rows that have in the cells duplicates symbols
I have a dataframe that has columns with strings and columns with floats. some values in the cells have two symbols like this: -0.015-0.156 ==> middle ‘-‘ is not ok, two dots not ok 0.014-0.106 ==> middle ‘-‘ is not ok, two dots not ok 0.013.0.156 ==> two dots not ok -0.015 ==…