289,241 questions
-2
votes
0
answers
30
views
Trouble displaying dataframe headers in PythonAnywhere
I am trying to display the headers of a data frame I created based on a csv file using the PythonAnywhere free version. I keep getting a huge error message and I don't understand what I did wrong.
...
-1
votes
1
answer
65
views
Reading txt file with read_csv() [closed]
I need to import a .txt file into a DataFrame using the pd.read_csv() command.
However, I keep getting errors like this:
Expected 2 fields in line 15, saw 7.
The file looks like this (I also ...
Best practices
0
votes
3
replies
84
views
How to access specific, indexed elements of a Pandas Dataframe for math?
What is the right/pythonic way to do math on a few indexed elements in a Pandas Dataframe?
I tried a few ways but they seem awkward and confusing:
df = pd.DataFrame({'x': [1, 2, 3, 4, 5, 6, 7, 9, ]})
...
0
votes
0
answers
21
views
Sklearn2pmml raises an error on 'classes_' parameter
I'm trying to create a PMML from a model, using this way :
from sklearn.preprocessing import LabelEncoder
y_h_train = LabelEncoder().fit_transform(y_train.copy(deep=True))
modele_label_encoded = ...
0
votes
1
answer
59
views
Pandas dataframe headers into a openpyxl table
Essentially I haven't been able to parse a pandas DataFrame into an Excel table properly, I have the output working but the headers remain being passed as if the were an extra row
ws.append([])
ws....
0
votes
1
answer
39
views
KeyError when trying to ftp from NASDAQ Other Symbols
I am trying to make a program to get a list of all (or at least almost all) USA listed stocks on all exchanges. I got AI to generate the following program suggestion:
import pandas as pd
from ftplib ...
1
vote
2
answers
73
views
How to store number as a text while exporting from pandas to excel
I have a DataFrame that contains an A/C number column, where some values are longer than 15 digits. When I export the DataFrame to Excel using .to_excel(), Excel automatically converts these long ...
1
vote
1
answer
51
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 ...
1
vote
0
answers
63
views
Why does DataFrame.apply() use axis=1 for rows instead of axis=0 in pandas? [duplicate]
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 ...
2
votes
1
answer
82
views
Different epoch time 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 = ...
0
votes
0
answers
49
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 ...
0
votes
0
answers
105
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 (...
1
vote
2
answers
138
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 ...
3
votes
2
answers
115
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 ...
-5
votes
1
answer
102
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, ...