All Questions
2,794
questions
1
vote
1
answer
26
views
Python Pandas difference in boolean indexing between ~ != and ==
I am confused about different results of boolean indexing when using ~ after != versus when using just ==
I have a pandas df with 4 columns:
dic = {
"a": [1,1,1,0,0,1,1],
"b&...
0
votes
1
answer
35
views
Create a new column based on other columns for time series data in pandas
I have the following pandas dataframe with columns May, June, and July.
Month
June
July
Aug
June
a
d
g
July
b
e
h
Aug
c
f
i
I want to create a several new columns with a 1 month forecast, 2 month ...
1
vote
3
answers
66
views
How to create a dynamic index in a data frame based on a catalog?
I have two diferent data frames. The first one is a catalog of diferent requests type and how many request i had at the moment.
data = {'Req Type': ['A', 'B', 'C', 'D'], 'Req No': [20, 21, 19, 18]}
...
1
vote
2
answers
46
views
Why is no warning thrown for indexing a Series of values with a bool Series that's too long?
I have the following code:
import pandas as pd
series_source = pd.Series([1, 2, 3, 4], dtype=int)
normal_index = pd.Series([True, False, True, True], dtype=bool)
big_index = pd.Series([True, False, ...
0
votes
2
answers
50
views
Why does pandas .reindex() not keep data with equivalent sized index? [duplicate]
Lets say we have this dummy data :
dates=pd.date_range("2020-02-01","2021-02-01",freq="MS")
features=["foo","bar"]
cols=pd.MultiIndex.from_product([...
2
votes
1
answer
63
views
How to predict the resulting type after indexing a Pandas DataFrame
I have a Pandas DataFrame, as defined here:
df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'],
'Age': [25, 30, 35],
'Location': ['Seattle', 'New York', 'Kona']...
3
votes
2
answers
70
views
unstack on single row index
data = {
'Store': ['Store_A', 'Store_A', 'Store_B', 'Store_B'],
'Product': ['Apples', 'Bananas', 'Apples', 'Bananas'],
'Sales': [200, 350, 150, 500]
}
df = pd.DataFrame(data)
df.set_index(...
1
vote
1
answer
24
views
TypeError: slice indices must be integers or None or have an __index__ method recordlinkage.Index
Could you please help to solve the issue with error regarding indices?
df18 =pd.DataFrame({'Index': [0,1,2,3,4,],
'Name': ['Anna', 'Jan', 'Pawel','Sonia', "Klaudia"],
'Age': [20,25,...
0
votes
2
answers
61
views
Is there a convenient way to index a pandas dataframe based on the approximate location of a number?
I am analyzing some optical spectra data and my dataframe indices are numbers that have some 9 decimal place accuracy. If I don't type in the exact index, the dataframe won't return a value. I am ...
2
votes
3
answers
79
views
How to use `pycountry.db.Country` objects as a `pd.DataFrame` index?
I am creating a dataset collecting data for a given set of countries. To avoid any ambiguity, I would like to use a pycountry.db.Country object to represent each country.
However, when setting the ...
1
vote
2
answers
43
views
Pandas reset_index() not working on grouped dataframe
I have a dataframe df as follows:
Year
Month
Rate
0
2022
1
0.1
1
2022
2
0.1
2
2022
3
0.1
3
2022
4
0.1
4
2022
5
0.1
5
2022
6
0.1
6
2022
7
0.1
7
2022
8
0.1
8
2022
9
0.1
9
2022
10
0.1
10
2022
...
0
votes
1
answer
36
views
Pandas data frame read_CSV: why automatically make first column data as index
I'm looking at sensor data with Pandas dataframes. The text file I have does not have an index field.
It starts with time data, but when I use this code to load data from a file into a Pandas data ...
3
votes
3
answers
63
views
Multiply two different Dataframes - Python
I have two tables:
Table 1: (Sales)
Code
2025
2026
2027
123
20000
21000
22000
456
10000
12000
14000
Table 2: (Inflation)
Code
2020
2021
2022
2023
2024
2025
2026
2027
2028
123
0.6
0.7
0.8
0.9
1
1....
1
vote
2
answers
51
views
filter pandas dataframe based on count of column value
I have a dataframe that looks like this -
import pandas as pd
sample_df = pd.DataFrame(columns=["A", "B"], data=[[1, "Red"], [2, "Blue"], [3, "Green"],...
2
votes
1
answer
54
views
Lookup by datetime in timestamp index does not work
Consider a date-indexed DataFrame:
d0 = datetime.date(2024,5,5)
d1 = datetime.date(2024,5,10)
df0 = pd.DataFrame({"a":[1,2],"b":[10,None],"c":list("xy")}, index=...