Category "pandas"

How to read .csv with a compound header into a xarray DataArray (using pandas)

Given a dataset with the following structure: time var1 var2 var2 var1 var3 loc1 loc1 loc2 loc2 loc1 1 11 12 13 14 15 2 21

formatting timedelta64 when using pandas.to_excel

I am writing to an excel file using an ExcelWriter: writer = pd.ExcelWriter(fn,datetime_format=' d hh:mm:ss') df.to_excel(writer,sheet_name='FOO') The writi

How to scale a dataframe with datetime field in it (as a index)?

I want to scale a dataframe, which raises the error as in the title (or below). My data: df.head() timestamp open high low close volume 0 2020-06-2

Pandas DataFrame: replace all values in a column, based on condition

I have a simple DataFrame like the following: I want to select all values from the 'First Season' column and replace those that are over 1990 by 1. In this e

Problem using IMF data API for a large number of countries

I am trying to download national account data from the API of the International Financial Statistics from the International Monetary Fund. I don't have any trou

How do I get a list of all the duplicate items using pandas in python?

I have a list of items that likely has some export issues. I would like to get a list of the duplicate items so I can manually compare them. When I try to use

Pandas: how can I generate "year-month" format column (period)?

In [20]: df.head() Out[20]: year month capital sales income profit debt 0 2000 6 -19250379.0 37924704.0 -4348337.0 25

TypeError: strptime() argument 1 must be str, not float

I'm having parsing errors on my code, below is the code and almost understandable dataset import numpy as np import pandas as pd from datetime import datetime

How to parse this JSON which starts with two square brackets?

I have a JSON File that starts with two square brackets. How do i parse the data from it? The type of the JSON is class 'list'. I have gone though many Stackove

Interpolate (or extrapolate) only small gaps in pandas dataframe

I have a pandas DataFrame with time as index (1 min Freq) and several columns worth of data. Sometimes the data contains NaN. If so, I want to interpolate only

Inplace Forward Fill on a multi-level column dataframe

I have the following dataframe: arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]

Creating an empty Pandas DataFrame, then filling it?

I'm starting from the pandas DataFrame docs here: http://pandas.pydata.org/pandas-docs/stable/dsintro.html I'd like to iteratively fill the DataFrame with valu

How to change the datetime tick label frequency for matplotlib plots

Below shows a plot of simulated data, which contains the xticks that I want to modify. By default, the pd.df.plot chooses dates that are approximately 3 months

Count groups of consecutive 1s in pandas

I have a list of '1's and '0s' and I would like to calculate the number of groups of consecutive '1's. mylist = [0,0,1,1,0,1,1,1,1,0,1,0] Doing it by hand g

Alternative to Qgrid for displaying "pretty" dataframes in notebooks

I wanted to use some library to have better display of pandas dataframe in notebooks (ie allow sorting of columns, filters etc). Qgrid seemed like a good-enough

Reading coef value from OLS regression results

I use pandas and statsmodels to do linear regression. However, i can't find any possible way to read the results. the results are displayed but i need to do som

AttributeError: module 'pandas' has no attribute 'core'

I have installed the tensorflow library on Windows, then my Pandas library stopped working, and after pandas importing appears the same issue as by importing th

How to apply a function to two columns of Pandas dataframe

Suppose I have a df which has columns of 'ID', 'col_1', 'col_2'. And I define a function : f = lambda x, y : my_function_expression. Now I want to apply the f

Check which columns in DataFrame are Categorical

I am new to Pandas... I want to a simple and generic way to find which columns are categorical in my DataFrame, when I don't manually specify each column type,

SQLAlchemy ORM conversion to pandas DataFrame

Is there a solution converting a SQLAlchemy <Query object> to a pandas DataFrame? Pandas has the capability to use pandas.read_sql but this requires use o