Skip to content

Tag: python

Convert Date to pandas from ISO 8601 format

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

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

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…

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:…

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 –