Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [pandas]

Pandas is a Python library for data manipulation and analysis, e.g. dataframes, multidimensional time series and cross-sectional datasets commonly found in statistics, experimental science results, econometrics, or finance. Pandas is one of the main data science libraries in Python.

6 votes
2 answers
3k views

pandas dataframe - change values based on column heading

I have a dataframe that looks like the following: In [74]: data2 Out[74]: a b c 2012-06-12 0 1 1 2012-06-13 1 1 0 2012-06-14 1 0 1 2012-06-15 1 0 1 2012-06-16 1 1 0 ...
Tony's user avatar
  • 170
4 votes
3 answers
7k views

Converting date/time in Pandas

I have stock ticker data in the following format: 40289.65972 40289.66319 40289.66667 and Excel is able to magically convert them to: 4/22/14 3:50 PM 4/22/14 3:55 PM 4/22/14 4:00 PM via "Format ...
vgoklani's user avatar
  • 11.5k
10 votes
1 answer
6k views

Converting data to missing in pandas

I have a DataFrame with a mix of 0's and other numbers. I would like to convert the 0's to missing. For example, I am looking for the command that would convert In [618]: a=DataFrame(data=[[1,2],[...
DanB's user avatar
  • 3,915
2 votes
1 answer
1k views

Python pandas to partially collapse 2d matrix

I would like to partially "collapse" a DataFrame/matrix and keep the structure intact by just summing the condensed values. For example, I have this: CHROM POS GENE DESC JOE ...
alexhli's user avatar
  • 409
4 votes
1 answer
943 views

Add seconds to python datetime excluding weekends

I am trying to add seconds to python datetime excluding weekends using pandas. The code below works, but I would like to know if there is a simpler way to achieve this. import datetime from pandas ...
UNagaswamy's user avatar
  • 2,118
7 votes
2 answers
954 views

Joining a Pandas series with a hierarchical index back to the source DataFrame

I'm trying to wrap my brain around pandas data structures and trying to use them in anger a bit. I've figured out that groupby operations result in a pandas series object. But I can't quite figure out ...
JD Long's user avatar
  • 60.5k
53 votes
4 answers
118k views

Slice Pandas DataFrame by Row

I am working with survey data loaded from an h5-file as hdf = pandas.HDFStore('Survey.h5') through the pandas package. Within this DataFrame, all rows are the results of a single survey, whereas the ...
ruben baetens's user avatar
0 votes
1 answer
3k views

Handle with European date format in python pandas

This question is somehow a continuation of this one. I've been able to correctly takes what I'm interested in a downloadable csv file as follow import time import urllib2 import csv import sys import ...
Nicola Vianello's user avatar
0 votes
1 answer
440 views

pandas: stacking DataFrames generated by apply

With a DataFrame, you can output Series when using DataFrame.apply to generate a new DataFrame with new columns a b c 0 -0.119342 0.286710 0.266750 1 -1.514301 0.556106 -...
duckworthd's user avatar
428 votes
15 answers
809k views

pandas: filter rows of DataFrame with operator chaining

Most operations in pandas can be accomplished with operator chaining (groupby, aggregate, apply, etc), but the only way I've found to filter rows is via normal bracket indexing df_filtered = df[df['...
duckworthd's user avatar
150 votes
11 answers
200k views

String concatenation of two pandas columns

I have a following DataFrame: from pandas import * df = DataFrame({'foo':['a','b','c'], 'bar':[1, 2, 3]}) It looks like this: bar foo 0 1 a 1 2 b 2 3 c Now I want to have ...
nat's user avatar
  • 1,551
1 vote
2 answers
831 views

Pandas messing up dataframe

I'm creating a data frame in Pandas— df_data = dict() for x in data: series = pandas.Series(x['value']['values'], index=x['value']['timestamps']) df_data[x['_id']] = series df = pandas....
user1569050's user avatar
  • 6,287
5 votes
2 answers
11k views

Pulling variable names when using pandas and statsmodels

I'm trying to access the names of variables from the results generated by statsmodels. I'll elaborate more after the example code. import scikits.statsmodels.api as sm import pandas as pd data = sm....
user1074057's user avatar
  • 1,802
0 votes
5 answers
2k views

Pandas: date_range error [closed]

I'm getting an error using pandas date_range function. I've given the trace below, and can provide more context, but it seems like something I'm really going to have to dig into myself to solve. So ...
scry's user avatar
  • 1,257
17 votes
5 answers
27k views

How to generate a list from a pandas DataFrame with the column name and column values?

I have a pandas dataframe object that looks like this: one two three four five 0 1 2 3 4 5 1 1 1 1 1 1 I'd like to generate a list of lists objects where ...
turtle's user avatar
  • 7,933

15 30 50 per page