I have a date it look like this how can i convert it to someting like this Answer If you want to do this using Pandas, you can use pandas to convert iso date to datetime object then strftime to convert timestamp into string format to apply it to a series of dates of DataFrame column you can replace iso_date
Tag: python
Sort arrays in alphabetical order and numeric order
So I have made the code above which fetches data from a .csv file and prints it out. I want to be able to print out the data in alphabetical and numerical order but I am not sure how to go about swapping them around. This is just a sample of data, the real list is about 100 lines long
Create multiple columns at once based off of existing columns
I have this dataframe df: I want to create two new columns at once which are simply the character length of the existing two columns. The result should look like this: I’ve tried to use for comprehension to generate the lists at once, such as so: but I get I would like to do more complex operations and …
Read nested JSON in a cell with Pandas
I recovered a list of ISO 3166-2 countries and regions in this Github repository. I managed to have a first look of the regions using the following code: Which gives the following output: name divisions Afghanistan {‘AF-BDS’: ‘Badakhshān’, ‘AF-BDG’: ‘Bādghīs’, &…
Django: Nested Loop In Template
In views.py above this loop creates a list of objects per each category. In the template below this loop prints a filtered object list per every item in the category list. The only thing I am missing is I do not now how to reference the category in the template. I pass the whole list in context, but {{categor…
Fastest way to get all first-matched rows given a sequence of column values in Pandas
Say I have a Pandas dataframe with 10 rows and 2 columns. Now that I am given a sequence of ‘col1’ values in a numpy array: I want to find the rows that have the first occurence of 3, 1 and 2 in ‘col1’, and then get the corresponding ‘col2’ values in order. Right now I am u…
Error with shape of passed value to pandas dataframe
I parsed a json object obtained from hidden api on website; after some trouble i get finally what i wanted but got an error creatinf the dataframe. Here’s the code: `The error i got is: “Shape of passed values is (13, 1), indices imply (13, 13)” In fact if i run for example odds1 i got this:…
Python: Use the “value” of a class instance as the value of a specified class instance attribute
I am relatively new to Python and have a question relating to accessing class instance attributes. Consider the example below My actual code is a bit more complex than this example; the motivation for requiring this functionality is that I do not want to write numpy_array.shape[0] or numpy_array.shape[1] thro…
Two while Loop Statements showing different results
I am new to python and struggling with 2 simple sets of code in which there is while loop used with a little difference (atleast in my opinion). These code should print ‘i’ while it is less than 6 but one set of code is printing ‘1 2 3 4 5 6’ and the other is printing ‘0 1 2
How to accept input from an enumerated list in Python?
So I have a list that I want to number using enumerate(), then have the user choose an item from the list using the corresponding number. Is there a way to do this? (This is broken code but hopefully, you get an idea of what I want to do) Answer It’s always a good idea to validate user input –