Combining two similar columns from 2 different tables with no relationship [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hi my project works on Django Python. What I want to achieve is since django tasty pie doesn't support combining two resources(no relationship b/w the tables), I need to come up with my own resource. Here I have 2 tables, Table A and B. There is no relationship b/w these 2 tables. But both the tables have a field/column named gname in common. So I want to get all the distinct gnames from both the tables and put it into one list (no duplicated values) and I need to display these gnames as a list in my template. Is there anyway to do that? Thanks in advance.

try:
gnames1 = list(A.objects.values_list('gname',flat=True).distinct())
gnames2 = list(B.objects.values_list('gname',flat=True).distinct())
gnames = list(set(gnames1+gnames2))
render(request, 'sampletemplate.html', {'gnames':gnames})

Set is a data structure that doesn't allow duplicate values.
You can add all the values from both the tables to it and I think you are good to go.
Python Sets

Related

How to extract the table in excel using openpyxl [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I have excel sheet having one sheet with 4 tables they are placed randomly. Out of the four tables, three tables have column name, except for one. Each table has 4 to 5 rows and 4 to 5 columns. How to extract all the tables without doing hard coding using Python. All tables are separated by some space.
Does this previous question
https://stackoverflow.com/questions/69255564/how-to-extract-different-tables-in-excel-sheet-using-python
help? The example code that can be adapted to just print all tables in all sheets. It does also use pandas.

What is the best way to store big data per user? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I just need some advice about what database should I use, and how should I store my data.
Namely I need to store big chunk of data per user, I was thinking about storing everything in JSON data, but I thought that I could ask you first.
So I am using Django, and for now MySql, I need to store like 1000-2000 table rows per user, with columns like First Name, Last Name, Contact info, and also relate it somehow to the user that created that list. Also I need this to be able to efficiently get data from database.
Is there any way of storing this big data per user?
Thank you!
I know pandas is a library that works very well for storing data. So maybe look into that and see what file formats are well documented with it.

Multiple field include exlude with python and mysql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
My api needs to be something like this:
api/search_fields=country_name,region,city,pincode,dma&exclude=false,true,true,false&country_name=india,pakistan&region=tamil nadu,jammu kashmir,&city=ahmedabad&pincode=112&dma=1
Means if country_name is excluded their correspoding region,city,pincode,dma will not come in result.Same way if region is exluded city,pincode,dma will not come in results of which all countries are excluded and which all regions are excluded.
How can i write mysql template in python for all these.
Although the question is very wide, I will try to answer.
The general idea is checking what the user has specified in the request and then hide absent columns in the output. We call it a view logic. You can take care of it in Controller or in Template directly.
Probably, it does not help you too much, but I cannot answer another way so broad question.

What's the difference between a hash table and a Python dictionary? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am starting to learn about the hash table data structure in C, and I've noticed (if I understand the concept correctly) that hash tables are awfully similar to python dictionaries. If I am incorrect and they are two completely different things, could someone explain to me what a hash table is without getting too technical? Thanks.
There is not really any difference between them. That's why python's dicts don't support duplicates. That is also why python has the function hash which python's dictionaries use by default.

Whats difference between models.py & forms.py? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am learning about Django & Python from past two weeks.though, my reading i came across models.py & forms.py. structure of both this is almost same. can anyone explain me whats the difference between them?
I also want to know where do i have to write the (<form> </form>) code. I mean in any html file or *.py file or where?
They are indeed very different in concept, albeit they can look similar. Let me explain:
Models define your business objects and data structures. They are the "entities" of the application wich have to be persisted in the database. Since it's a definition of the objects and their attributes, you define "fields". They represent the data structure and persistence of the app.
Forms are meant to make easier to get input from the user, validate data, render html and recover values supplied by the user. They also have fields but you have to note they don't map to a database and they don't represent an entity. They represent the "inputs" of the app.

Categories