Skip to main content

All Questions

Tagged with
0 votes
2 answers
52 views

Conversion of Dataframe to namedtuple of numpy arrays

I need to convert my pandas dataframe to tuple of numpy arrays. My code is like, import pandas as pd data = {'Class':[10., 11., 9., 8.], 'Age':[27., 24., 22., 32.], 'Mark':[76., 56., ...
Aristocrat's user avatar
0 votes
1 answer
129 views

Print named tuple value in a list

A function is returning me the below list of named tuples: [popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768), popenfile(path='/var/log/monit.log', fd=4, position=...
Saga Harby's user avatar
1 vote
1 answer
33 views

Is it be possible to give custom names to the newly created type that is pushed to the end of a tuple type, without affecting other argument names?

Here i have a type that takes a tuple type with a fixed number of parameters, and also includes an array of strings as the final parameter. I want to give the tuple type parameters custom names a, b ...
cyrus-d's user avatar
  • 815
-1 votes
1 answer
34 views

How to type a returned Array inside an Array? [closed]

return [[x, y], d, prevRing, prevRingPosition] That is my return statement and I want to make a type for its function type nextUlamReturn = [ number[], d: number, prevRing: number, ...
Felix Prackwieser's user avatar
-1 votes
1 answer
462 views

How to find delete a student record in Python (example on a Students Mark exercise)

Start a new Python script and write some suitable input commands to store three items of data into three variables: Student Name, Coursework Mark, and Exam Mark. The inputs for coursework mark and ...
tab's user avatar
  • 15
0 votes
1 answer
48 views

Python data json dictionary

I wanted to read tar.json file, so I write: import json with open('tar.json', "r", encoding='utf-8') as read_file: data = json.load(read_file) and print it as dictionary, for ...
Malum Phobos's user avatar
0 votes
1 answer
286 views

Use Tuple values in Object initalizer syntax

I'm trying to initialize properties of an object I am creating with the values of a named tuple. Something like this public Person DoIt() { return new Person { (First, Last) = GetFirstAndLast(id)...
comecme's user avatar
  • 6,286
1 vote
0 answers
140 views

Creating tuples of images and distributing the tuples into training and testing sets

I've a simple program that creates a bunch of images. The problem is, they need to be ordered into tuples of three images so that the images in each tuple are kept together when they are distributed ...
Brian Droncheff's user avatar
0 votes
1 answer
40 views

How to create a tuple from dictionaries?

from collections import namedtuple BookPlan = namedtuple('Book', ['size', 'weight']) books = BookPlan(3, 5), BookPlan(4, 9) i=0 book={} while (i<3): book['size'] = i book['weight'] = i*...
Vad_S's user avatar
  • 23
1 vote
2 answers
392 views

Remove duplicates in a tuple of tuples

I have the following tuple of tuples: # my Noah's Ark myanimals = (('cat', 'dog'), ('callitrix', 'platypus'), ('anaconda', 'python'), ('mouse', 'girafe'), ... ,('platypus', 'callitrix')) Since ...
Copernicus's user avatar
3 votes
4 answers
2k views

Dictionary of (named) tuples in Python and speed/RAM performance

I'm creating a dictionary d of one million of items which are tuples, and ideally I'd like to access them with: d[1634].id # or d[1634]['id'] d[1634].name # or d[1634]['name'] d[1634]....
Basj's user avatar
  • 44.9k
4 votes
1 answer
1k views

Can namedtuples be used in set()?

I know that namedtuple is a factory function to create classes with immutable data fields. I'm assuming they are hashable so that they can be used in sets. My worry is if there are any gotchas ...
ajoseps's user avatar
  • 2,041
-1 votes
2 answers
5k views

AttributeError: 'tuple' object has no attribute 'get' in Python 3

I have two lists. one of candidates and one of votes received. I want to sort them descending by votes received. Zipping works fine. When I print the type of the resultant list it comes back as class ...
Wolfe's user avatar
  • 97
0 votes
1 answer
243 views

What is the fastest way to find the average for a list of tuples in Python, each tuple containing a pair of namedtuples?

import numpy as numpy from collections import namedtuple from random import random Smoker = namedtuple("Smoker", ["Female","Male"]) Nonsmoker = namedtuple("...
Paw in Data's user avatar
  • 1,432
29 votes
1 answer
18k views

What are “named or labeled tuples” in Typescript?

Reading the changes in Typescript 4.0, I found the new feature: Labeled Tuple Elements I thought elements could either be indexed by numbers (like in tuples and lists) or by keys (like in dicts). I ...
zerocewl's user avatar
  • 12.5k

15 30 50 per page