tagged [pandas]

Pandas rename column by position?

Pandas rename column by position? I was just wondering if I can rename column names by their positions. I know how to rename them by their actual names using: `df.rename(columns = {})` How do I do it ...

22 Mar at 03:56

How to sort a Pandas DataFrame by index?

How to sort a Pandas DataFrame by index? When there is a DataFrame like the following: How can I sort this dataframe by index with each combination of index and column value intact?

26 Jan at 05:43

Pandas: drop a level from a multi-level column index?

Pandas: drop a level from a multi-level column index? If I've got a multi-level column index: How can I drop the "a" level of that index, so I end up with:

6 Mar at 18:58

Pandas DataFrame to List of Dictionaries

Pandas DataFrame to List of Dictionaries I have the following DataFrame: which I want to translate it to list of dictionaries per row ``` rows = [ { 'customer': 1, 'item1': 'apple', 'ite...

Pandas: Convert Timestamp to datetime.date

Pandas: Convert Timestamp to datetime.date I have a pandas column of Timestamp data How can check equivalence of these objects to `datetime.date` objects of the type

21 Dec at 00:22

Delete a column from a Pandas DataFrame

Delete a column from a Pandas DataFrame To delete a column in a DataFrame, I can successfully use: But why can't I use the following? Since it is possible to access the Series via `df.column_name`, I ...

6 Feb at 03:5

How to create a dictionary of two pandas DataFrame columns

How to create a dictionary of two pandas DataFrame columns What is the most efficient way to organise the following pandas Dataframe: data = into a dictionary like `alphabet[1 : 'a', 2 : 'b', 3 : 'c',...

4 Dec at 19:54

Dropping infinite values from dataframes in pandas?

Dropping infinite values from dataframes in pandas? How do I drop `nan`, `inf`, and `-inf` values from a `DataFrame` without resetting `mode.use_inf_as_null`? Can I tell `dropna` to include `inf` in i...

20 Jun at 01:23

Combine two columns of text in pandas dataframe

Combine two columns of text in pandas dataframe I have a 20 x 4000 dataframe in Python using pandas. Two of these columns are named `Year` and `quarter`. I'd like to create a variable called `period` ...

13 Aug at 23:27

Multiple aggregations of the same column using pandas GroupBy.agg()

Multiple aggregations of the same column using pandas GroupBy.agg() Is there a pandas built-in way to apply two different aggregating functions `f1, f2` to the same column `df["returns"]`, without hav...

Convert Pandas Column to DateTime

Convert Pandas Column to DateTime I have one field in a pandas DataFrame that was imported as string format. It should be a datetime variable. How do I convert it to a datetime column and then filter ...

29 Jan at 18:42

Groupby value counts on the dataframe pandas

Groupby value counts on the dataframe pandas I have the following dataframe: I want to group it by `id` and `group` and calculate the number of each term for this id, group pair. So in

How to sort a dataFrame in python pandas by two or more columns?

How to sort a dataFrame in python pandas by two or more columns? Suppose I have a dataframe with columns `a`, `b` and `c`, I want to sort the dataframe by column `b` in ascending order, and by column ...

Creating a zero-filled pandas data frame

Creating a zero-filled pandas data frame What is the best way to create a zero-filled pandas data frame of a given size? I have used: Is there a better way to do it?

24 Feb at 16:4

How do I create test and train samples from one dataframe with pandas?

How do I create test and train samples from one dataframe with pandas? I have a fairly large dataset in the form of a dataframe and I was wondering how I would be able to split the dataframe into two ...

10 Jun at 17:24

Python Pandas GroupBy get list of groups

Python Pandas GroupBy get list of groups I have a line of code: The colors are Red, Blue, Green, Yellow, Purple, Orange, and Black. How do I return this list? For similar attributes, I use x.Attribute...

4 Mar at 00:18

What is dtype('O'), in pandas?

What is dtype('O'), in pandas? I have a dataframe in pandas and I'm trying to figure out what the types of its values are. I am unsure what the type is of column `'Test'`. However, when I run `myFrame...

8 Jun at 23:47

Get the name of a pandas DataFrame

Get the name of a pandas DataFrame How do I get the name of a DataFrame and print it as a string? Example: `boston` (var name assigned to a csv file)

16 Dec at 10:29

convert array into DataFrame in Python

convert array into DataFrame in Python When I input the code above, I get this answer: ![enter image description here](https://i.stack.imgur.com/gAZsb.png) But how do I change the column name?

27 Jul at 18:19

Pandas - dataframe groupby - how to get sum of multiple columns

Pandas - dataframe groupby - how to get sum of multiple columns This should be an easy one, but somehow I couldn't find a solution that works. I have a pandas dataframe which looks like this: ``` inde...

Writing a pandas DataFrame to CSV file

Writing a pandas DataFrame to CSV file I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using: And getting the following error: - -

19 Dec at 08:51

Split a large pandas dataframe

Split a large pandas dataframe I have a large dataframe with 423244 lines. I want to split this in to 4. I tried the following code which gave an error? `ValueError: array split does not result in an ...

26 Jun at 09:1

Python Pandas: How to read only first n rows of CSV files in?

Python Pandas: How to read only first n rows of CSV files in? I have a very large data set and I can't afford to read the entire data set in. So, I'm thinking of reading only one chunk of it to train ...

14 Feb at 01:51

How do I read a large csv file with pandas?

How do I read a large csv file with pandas? I am trying to read a large csv file (aprox. 6 GB) in pandas and i am getting a memory error: Any help on this?

10 Apr at 14:23

How to delete the last row of data of a pandas dataframe

How to delete the last row of data of a pandas dataframe I think this should be simple, but I tried a few ideas and none of them worked: ``` last_row = len(DF) DF = DF.drop(DF.index[last_row]) #

14 Feb at 05:28