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 ...
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?
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:
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...
- Modified
- 30 Mar at 10:26
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
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 ...
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',...
- Modified
- 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...
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` ...
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 ...
- Modified
- 1 Nov at 22:31
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?
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 ...
- Modified
- 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...
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...
- Modified
- 19 Apr at 13:23
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)
- Modified
- 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?
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
- Modified
- 4 Nov at 07:50
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: - -
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...
- Modified
- 28 Apr at 07:35
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 ...
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 ...
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]) #