Skip to main content
0 votes
1 answer
32 views

How to assign int input value as column name in pandas [duplicate]

I need to take an integer input value, assign it to a variable, and then use that variable as a column name to get data from a pandas DataFrame. Data: 1 10 20 30 2 40 50 60 Steps: Assign input to ...
madhu chatim's user avatar
0 votes
0 answers
43 views

Why does DataFrame.apply() use axis=1 for rows instead of axis=0 in pandas?

I was reading the pandas documentation: pandas.DataFrame.apply documentation In this definition, it seems to me like the use of axis is the exact opposite of what it means in other functions? To apply ...
Jacoberu's user avatar
0 votes
1 answer
41 views

Different epoch from the same datetime

Here is my code: import pandas as pd import datetime df = pd.DataFrame({'str_date': ['2023091004']}) df['epoch'] = pd.to_datetime(df['str_date'], format='%Y%m%d%H').astype(int) // 10**9 dt = ...
user1700890's user avatar
  • 7,798
0 votes
0 answers
43 views

entsoe-py query_imbalance_(prices|volumes) fails with ValueError: invalid literal for int(): '1,346' in parser — best fix?

I’m fetching ENTSO-E imbalance prices/volumes with entsoe-py and hit a parser crash because the <position> field contains a thousands separator comma (e.g. "1,346"), which int() can’t ...
EmmaW23's user avatar
0 votes
0 answers
94 views

How to get value of cell in dataframe

I'm new to Python, so please be lenient. I want to read the value of a single cell from a dataframe based on the selected row. I do this as below, but I get the value not when I click on a record (...
Szymon Tomtała's user avatar
1 vote
3 answers
121 views

After encoding my categorical columns in a pandas dataframe, I was left with too many columns. How can I drop some?

I am using Python with a pandas dataframe, it is a CSV of Steam games, and I have the categorical columns of publishers, developers, categories, genres, and tags, but categories, genres, and tags are ...
Luciano Elish's user avatar
3 votes
2 answers
112 views

Calculate cumulative value based on another column [duplicate]

Having this kind of pandas dataframe df = pd.DataFrame({ 'ts_diff':[0, 0, 738, 20, 29, 61, 42, 18, 62, 41, 42, 0, 0, 729, 43, 59, 42, 61, 44, 36, 61, 61, 42, 18, 62, 41, 42, 0, 0] }) ts_diff - is ...
ihtus's user avatar
  • 2,863
-5 votes
1 answer
100 views

Using for loop to find a common value for every time another common value appears

import pandas as pd a=1 b=2 c=3 for n in range(10, len(df)-1): if df.loc[n].isin([a]).any() and df.loc[n].isin([b]).any() : for x in range(0, ...
Kan's user avatar
  • 45
0 votes
0 answers
61 views

How can I keep the first occurrence of repeated values in the same column in Pandas and delete the others? [closed]

I have a DataFrame and I want to keep only the first occurrence of repeating values in the same column and delete the others. Sample data: import pandas as pd df = pd.DataFrame({ "id": [...
Wendzara's user avatar
Best practices
0 votes
7 replies
114 views

Value count accuracy

I was trying to calculate the accuracy of my roberta label and pre existing dataset label i was confused on how to operate pandas's value_counts(), i dont know how to do operations on it before, the ...
Fauzan Anggito Wicakson's user avatar
3 votes
3 answers
168 views

Filter a pandas df: per group, keep only non-null rows if we have them, else keep a single null row

Hopefully the title is reasonably intuitive, edits welcome. Say I have this dataframe: df = pd.DataFrame({'x': ['A', 'B', 'B', 'C', 'C', 'C', 'D', 'D'], 'y': [None, None, 1, 2, 3, 4,...
Hendy's user avatar
  • 10.7k
Best practices
0 votes
5 replies
163 views

What is the ideal production-grade infrastructure to deploy a Python FastAPI service for computing option Greeks (e.g., Black–Scholes)?

I am building a python service to compute Greek values using python, but I have never worked on python, and I would appreciate advice from the experienced python devs as it would help me a lot. FLOW ...
NOOB DEV's user avatar
2 votes
1 answer
111 views

Concatenate Tables Based on Column Information in Python [duplicate]

I have a dataframes pulled from a file. The variable with all these dataframe names is: Data_Tables. These dataframes all have the same columns, and I want to concatenate the dataframes based on the ...
Jon S's user avatar
  • 55
-3 votes
0 answers
78 views

Convert datetime.timedelta to int [closed]

There are already multiple questions like this and I also tried AI, but so far no luck. Here is my example: import datetime import pandas as pd df = pd.DataFrame({ 'start_date': [datetime....
user1700890's user avatar
  • 7,798
2 votes
4 answers
119 views

How to find a common value using if statement

I am still a beginner in python. I am trying to find a common value with if statement, import pandas as pd df = pd.read_csv("data.csv") for n in range(2, len(df)): if df.loc[n].isin([2]...
Kan's user avatar
  • 45

15 30 50 per page
1
2 3 4 5
19283