Skip to main content

All Questions

Tagged with
2 votes
0 answers
46 views

Any dict-like mappable objects in Python that only show preview of contents when __repr__?

I'm looking for an object I can use to store largish dataframes and sklearn objects. Ideally I would like to store them as pd.Series because it has the behavior I'm looking for in that I can do the ...
O.rka's user avatar
  • 30.5k
2 votes
2 answers
1k views

How to enable row[col_name] syntax with Namedtuple Pandas from df.itertuples()

We have a DataFrame with many columns and need to cycle through the rows with df.itertuples(). Many column names are in variables and accessing the namedtuple row with getattr() works fine but is not ...
mpa's user avatar
  • 78
2 votes
2 answers
1k views

Why do tuples become strings after saving to csv and reloading the dataframe (pandas)?

import pandas as pd from random import random from collections import namedtuple Smoker = namedtuple("Smoker", ["Female","Male"]) Nonsmoker = namedtuple("...
Paw in Data's user avatar
  • 1,432
-1 votes
1 answer
41 views

How to deal with parsing an arbitrary number of lists into a dictionary

I am parsing an XMI/XML data structure into a pandas dataframe by first decomposing it into a dictionary. When I encounter a named tuple in a list in my XMI, there appear to be a maximum of two named ...
horcle_buzz's user avatar
  • 2,151
1 vote
2 answers
595 views

Efficient insertion of named tuple into pandas data frame [duplicate]

I have a named tuple called "rows" if I print it, it would look as shown below. How do I efficiently (not in for loop) insert this into a pandas data frame so that I can use it to plot graphs. (Number ...
reddi hari's user avatar
0 votes
2 answers
4k views

How to append row from itertuples to dataframe withouth losing the index in Python?

I have the following problem: I have a DataFrame df which looks like this: eqpid recpid queuetime trackintime trackouttime 3723 A XYZ 2017-01-01 03:14:58 2017-...
Kai Schelthoff's user avatar
6 votes
2 answers
2k views

Convert a pandas dataframe into a list of named tuple [duplicate]

I am looking for the most efficient way to convert a pandas DataFrame into a list of typed NamedTuple - below is a simple example with the expected output. I would like to get the correct type ...
Michael's user avatar
  • 2,526
4 votes
2 answers
7k views

How to convert a pandas dataframe to namedtuple

How to convert a pandas dataframe to namedtuple? This task is going towards multiprocessing work. def df2namedtuple(df): return tuple(df.row)
gcamargo's user avatar
  • 3,911
2 votes
2 answers
430 views

Passing Column Names from a tuple to Pandas

My Scenario looks like this, where i have identified the columns having NaN values using, nan_cols=tuple(train.columns[train.isnull().sum()>0]) Now, I need to find the correlation between these ...
Kavi Kumaran's user avatar
6 votes
1 answer
17k views

NamedTuple to Dataframe

I am working on retrieving metadata from youtube channels and it's videos. Everything is going fine, but currently I am struggling to put all the information in a dataframe which I need. Here is the ...
Jazz's user avatar
  • 465
-1 votes
1 answer
372 views

save a named tuple in all rows of a pandas dataframe

I'm trying to save a named tuple n=NamedTuple(value1='x'=, value2='y') in a row of a pandas dataframe. The problem is that the named tuple is showing a length of 2 because it has 2 parameters in my ...
Nickpick's user avatar
  • 6,471
1 vote
1 answer
478 views

Python - Access one part of a named tuple inside a two-dimensional list

In Python, I have row data that I'm trying to set to a pandas data frame. However the cell data is a named tuple so my output data contains: Cell(r=1,c=2,v='value'). All I want is the v from the ...
mikeh's user avatar
  • 13
2 votes
1 answer
575 views

fillna with a namedtuple or any other class pandas

Is there any way to fillna with a namedtuple in python? I am getting this TypeError: from collections import namedtuple import pandas as pd import numpy as np df = pd.DataFrame([0, 0, 0, 0, np.nan, ...
Steven G's user avatar
  • 16.9k
5 votes
2 answers
1k views

Nested dictionary of namedtuples to pandas dataframe

I have namedtuples defined as follows: In[37]: from collections import namedtuple Point = namedtuple('Point', 'x y') The nested dictionary has the following format: In[38]: d Out[38]: {1: {...
snowleopard's user avatar
27 votes
2 answers
58k views

How do I create pandas DataFrame (with index or multiindex) from list of namedtuple instances?

Simple example: from collections import namedtuple import pandas Price = namedtuple('Price', 'ticker date price') a = Price('GE', '2010-01-01', 30.00) b = Price('GE', '2010-01-02', 31.00) l = [a, b] ...
MikeRand's user avatar
  • 4,818