Category "pandas"

KeyError while reading a CSV file in Python

I am trying to plot the fall of an object (an optical fork to be precise) as a function of time in order to verify that the law of gravity is indeed 9.81. The d

Python: Reading a Windows generated csv with carriage return in column

I'm working on a Python program that needs to read csv files that are produced on a Windows 2012 server machine. The aim of the Python code is to give a min/max

How to exclude weekends and holidays from finding the difference between two dates in python

I need to find the difference between 2 dates where certain end dates are blank. I am need to exclude the weekends, as well as the holidays when calculating the

reading data-frame with missing values

I am trying to read some df with few columns and few rows where in some rows data are missing. For example df looks like this, also elements of the df are separ

Pandas MultiIndex match on one index level

I have a pandas MultiIndex object where the first level is a regular increasing index of ints, and the second level contains other integers that may or may not

Read entire row if a specific column has background color in excel sheet using Python

I have an excel sheet which has few columns with background color. I need to fetch all rows which has background color in column B. I tried with styleframe but

How to plot multiple chart on one figure and combine with another?

# Create an axes object axes = plt.gca() # pass the axes object to plot function df.plot(kind='line', x='鄉鎮別', y='男', ax=axes,figs

How to plot multiple chart on one figure and combine with another?

# Create an axes object axes = plt.gca() # pass the axes object to plot function df.plot(kind='line', x='鄉鎮別', y='男', ax=axes,figs

How to plot multiple chart on one figure and combine with another?

# Create an axes object axes = plt.gca() # pass the axes object to plot function df.plot(kind='line', x='鄉鎮別', y='男', ax=axes,figs

Pandas: imputing descriptive stats using a groupby with a variable

I have a data frame like this: input_df = pd.DataFrame({"sex": ["M", "F", "F", "M", "M"], "Class": [1, 2, 2, 1, 1], "Age":[40, 30, 30, 50, NaN]}) What I want t

How to fix the plot using iteration through the subplots?

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("population.csv") fig, axs = plt.subplots(nrows=2, ncols=2) for col, ax in zip(df.column

merging two excel files and then removing duplicates that it creates

I've just started using python so could do with some help. I've merged data in two excel files using the following code: # Import pandas library import pandas a

How to make a loop of random column combinations without repeating the combination in pandas dataframe?

I have a pandas dataframe that has 4 columns (A,B,D,E,F,G). I want to randomize each combination into 4 combinations (e.g. ABDE, ADEF, AEFG). And then add the c

How to save the Pandas dataframe from pd.crosstab as a figure (with render_mpl_table)?

I'm trying to save output from crosstab as an image. I found a great solution here How to save the Pandas dataframe/series data as a figure?. However, I am not

How to combine multi excel workbook into single workbook with multiple worksheets

I have 3 workboooks with single sheets.I need to combine all workbooks into single workbook with 3 sheets. I tried the below code : from pandas import ExcelWrit

Extracting specific number of rows from dataframe

I have a csv file having two columns i.e. imagename and ID. There are multiple image names for same ID as shown in picture. Number of image names against id is

Importing a data frame from CSV file using Pandas with column name having spaces

I am trying to import a data frame from a .csv file which contains Per Capita Income. Moreover, in the above mentioned file the column name is Per Capita Income

tag occurrences of a value multiple times inn column based on dates using pandas [duplicate]

Below is my dataframe: df = pd.DataFrame({'ID':[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'date': ['2020-12-1', '2020-12-2', '20

How to plot Dataframe for many rows?

I have a dataset where each row plots an ECG, with 50k rows, 181 columns and has 4 classes, represented in the last column (0, 1, 2, 3). So, I need to "convert"

How to combine multiple set of columns in a dataframe to single one? [duplicate]

I have a dataframe as follows Cycle A_0 A_1 A_2 A_3 B_0 B_1 B_2 B_3 1 3 4 5 6 1 4 5 1 8 5 3 1 0 8 6 4 2 7 9 1 6 1 0 2 3 3 5 9 1 0 3 8 3 th