Tag: pandas

52 votes
8 answers
1K views
dropping infinite values from dataframes in pandas?

what is the quickest/simplest way to drop nan and inf/-inf values from a pandas DataFrame without resetting mo

avatar
Scot
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
638 views
How to take column-slices of dataframe in pandas

I load some machine learning data from a CSV file. The first 2 columns are observations and the remaining colu

avatar
Basil
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
2.8K views
What does axis in pandas mean?

Here is my code to generate a dataframe: import pandas as pd import numpy as np dff = pd.DataFrame(np.random

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
60 votes
9 answers
1.3K views
Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?

I have a Numpy array consisting of a list of lists, representing a two-dimensional array with row labels and c

avatar
Sena
0 1 0 9
asked 07 September, 2021
53 votes
13 answers
2.3K views
Converting between datetime, Timestamp and datetime64

How do I convert a numpy.datetime64 object to a datetime.datetime (or Timestamp)? In the following code, I cr

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
53 votes
10 answers
2.5K views
Pandas conditional creation of a series/dataframe column

I have a dataframe along the lines of the below: Type Set 1 A Z 2 B Z

avatar
Janella
0 1 0 9
asked 07 September, 2021
60 votes
10 answers
1.8K views
Pandas read_csv low_memory and dtype options

When calling df = pd.read_csv('somefile.csv') I get: /Users/josh/anaconda/envs/py27/lib/pytho

avatar
Fabian
0 1 0 9
asked 07 September, 2021
59 votes
7 answers
2.9K views
pandas create new column based on values from other columns / apply a function of multiple columns, row-wise

I want to apply my custom function (it uses an if-else ladder) to these six columns (ERI_Hispanic, ERI_AmerInd

avatar
Alphonso
0 1 0 9
asked 07 September, 2021
62 votes
15 answers
744 views
Convert pandas dataframe to NumPy array

I am interested in knowing how to convert a pandas dataframe into a NumPy array. dataframe: import numpy as

avatar
Patsy
0 1 0 9
asked 07 September, 2021
53 votes
11 answers
1.3K views
How do I select rows from a DataFrame based on column values?

How can I select rows from a DataFrame based on values in some column in Pandas? In SQL, I would use: SELECT *

avatar
Freida
0 1 0 9
asked 07 September, 2021
54 votes
29 answers
2.8K views
How to iterate over rows in a DataFrame in Pandas

I have a DataFrame from Pandas: import pandas as pd inp = [{'c1':10, 'c2':100}, {'c1

avatar
Frederick
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
368 views
"Large data" workflows using pandas

I have tried to puzzle out an answer to this question for many months while learning pandas. I use SAS for my

avatar
Robyn
0 1 0 9
asked 07 September, 2021