Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
397 views

Using python, how can I take the values from 2021-09-13 to 2021-09-16? I tried the following: date_start = df['date'].iloc[-4] #2021-09-13 date_end = df['date'].iloc[-1] #2021-09-16 df = df.loc[...
kobo's user avatar
  • 45
0 votes
0 answers
55 views

df = pd.read_excel(excelName) df.columns=df.columns.str.strip() print(df.columns.tolist()) # print result is ['序号', '学号', '姓名', '文件位置', '邮箱地址'] print(df.loc['文件位置']) It seems I have ...
ry jin's user avatar
  • 1
4 votes
3 answers
3k views

I can't understand why I'm getting KeyError: Timestamp('...') when using loc on date index. With given df: dtypes are datetime64[ns], int, int, DATE1 is index DATE1 VALUE2 VALUE3 2021-...
Kalik's user avatar
  • 214
0 votes
1 answer
349 views

is it possible to use loc and replace functions to replace part of the column name for a range of columns? I've tried combining the replace and loc functions in a couple of variation, however, was ...
ManOnTheMoon's user avatar
1 vote
1 answer
987 views

I have a question regarding the loc function for my pandas DataFrame. First I want to check if the person is a student, then I would like to assign to first value of the list 'Course' for that ...
olive's user avatar
  • 199
1 vote
3 answers
166 views

For context, I'm trying to filter out rows in my dataframe that only belong to the year 2021. This is my script code: test = all_SS_batting_columns.loc[all_SS_batting_columns['Year'] == '2021'] but it ...
tatisbogaerts's user avatar
4 votes
1 answer
5k views

Is there any way to select the row by index (i.e. integer) and column by column name in a pandas data frame? I tried using loc but it returns an error, and I understand iloc only works with indexes. ...
Ricardo Milhomem's user avatar
-1 votes
1 answer
67 views

I have defined a function as shown. def calculate_mass_loss(group, idnum): """ Calculates mass loss on star referenced by idnum due to high mass stars Parameters -------...
Bridget Marchington's user avatar
-1 votes
1 answer
44 views

that is my date I want to choose myDates=['2021-02-24', '2021-02-26','2021-02-27', '2021-03-06', '2021-04-4', '2021-04-05', '2021-04-06', '2021-04-07', '2021-04-08','2021-04-13', '2021-04-14',...
Imri Zadak's user avatar
0 votes
2 answers
81 views

I have an csv data set that I imported in Jupyter and stored under inp0. I'm trying to create price bucket for these using .loc function in pandas bet getting below error. My Code: inp0.loc[inp0.price=...
Apekshit Dhoke's user avatar
0 votes
1 answer
1k views

df_state_group: Index State assigned_airport 4 Florida NaN 5 Florida NaN 6 Florida NaN 7 Florida NaN df1: Index State assigned_airport 0 Washington NaN 1 New York NaN 2 Illinois NaN 3 Texas NaN 4 ...
Moe's user avatar
  • 25
-2 votes
1 answer
376 views

I have this python script, this is just a part of it, it works but for just 2 lines I'm having troubles: not_marketo.loc['Marketo DEP'] = "NO" yes_marketo.loc[:,'Marketo DEP'] = C I have ...
Berny's user avatar
  • 143
0 votes
2 answers
77 views

Does anybody know, if its possible to switch the colors, so that i can distinguish every row instead of every column ? And how do I add in a legend, where i can see which player (one color for each ...
keb's user avatar
  • 11
1 vote
1 answer
2k views

I'm trying to use LOC with an AND condition. It works fine with OR conditions, but I can't get it to work with ANDs when there are duplicate values in a column. def locreplace(df,col,needle,replace,...
Sarah Eaglesfield's user avatar
1 vote
1 answer
182 views

I have two data frames and I want for each line in one data frame to locate the matching line in the other data frame by a certain column (containing some id). I thought to go over the lines in the ...
user3599541's user avatar
2 votes
1 answer
239 views

Dataframe data will be : COL1 COL2 COL3 100 200 300 101 201 301 102 202 302 103 203 303 Expected output: Format as HBase (Columnar fashion) Consider COL1 as KEY_COLUMN vaue KEY_COLUMN KEY VALUE 100 ...
Priyan's user avatar
  • 21
0 votes
1 answer
159 views

using df to select two columns col_1 and col_2 after groupby and loc and store at variable a in dataframe format Python Code import pandas as pd import numpy as np df = pd.DataFrame(dict(Gender=['M', ...
Mary's user avatar
  • 797
1 vote
0 answers
31 views

I am wondering what is the difference between these two lines: data.loc[(data['MINIMUM_PAYMENTS'].isnull()==True)]['MINIMUM_PAYMENTS'] data.loc[(data['MINIMUM_PAYMENTS'].isnull()==True),'...
ayhanizmir's user avatar
1 vote
2 answers
57 views

I would like to replace certain value-thresholds in a df with another value. For example all values between 1 and <3.3 should be summarized as 1. After that all values between >=3.3 and <10 ...
Neihilrach's user avatar
1 vote
0 answers
94 views

Can someone elaborate on the difference between using .loc and not in the examples below? What is the benefit of using: rslt_df = dataframe[dataframe['Percentage'] > 70], as opposed to rslt_df = ...
maroulator's user avatar
0 votes
1 answer
666 views

I have a DataFrame with a list of returns data. One row in the DataFrame contains the return for the benchmark, 'ASX', which in this example has a value of 6. (Values are updated using market data, so ...
Marmot's user avatar
  • 79
-1 votes
2 answers
100 views

I have a DF which is quite big. A snippet like the one shown below. SrNo | Merchant | Revenue | Currency 1 | UBER SR | 123 | INR 2 | UBER (SR)| 123 | INR 3 | SR UBER | 123 | ...
Anukriti Singh's user avatar
0 votes
1 answer
984 views

I have a list of dataframes (lst_dfs) of which i want to subset columns using a list of partial column names (lst). The list of the columns needs to be applied with startswith as sometimes the end of ...
b101's user avatar
  • 297
0 votes
4 answers
51 views

I have this data frame: data = {name: ['a', 'a','b', 'c', 'd', 'b', 'b', 'a', 'c'], number: [32, 25, 9 , 43,8, 5, 11, 21, 0] } and I want to get min number for each name where data in the ...
WhoIsKi's user avatar
  • 117
6 votes
2 answers
5k views

I have the following problem: in a df, I want to select specific rows and a specific column and in this selection take the first n elements and assign a new value to them. Naively, I thought that the ...
My Work's user avatar
  • 2,560
0 votes
2 answers
179 views

I have been practicing with pandas and have the following problem. I have been practicing with an Olympic medal data set where the countries are listed in one column, and the medals in subsequent ...
LJM's user avatar
  • 57
1 vote
1 answer
654 views

I noticed this today and wanted to ask because I am a little confused about this. Lets say we have two df's df = pd.DataFrame(np.random.randint(0,9,size=(5,3)),columns = list('ABC')) A B C 0 ...
rhug123's user avatar
  • 8,880
1 vote
1 answer
2k views

I have a df of car miles per gallon data, which are int (as far as I can tell). Using Pandas, I'm filtering with df.loc[(df['Horsepower'] >90)] which is giving me the results I expect - cars with &...
Yasser Al Kindi's user avatar
0 votes
2 answers
792 views

I'm crossing the information into two tables. I want to get the information from the column Register Number in the table profile and put it into the column Delivers, which I just created, into the ...
Marlon Teixeira's user avatar
-3 votes
3 answers
3k views

This code isn't working in Jupyter IDE. I can't find my mistake. Please help. The first 5 rows of the dataframe I am using is shown here:
Dynamo's user avatar
  • 51
11 votes
2 answers
1k views

Problem Pandas seems to support using df.loc to assign a dictionary to a row entry, like the following: df = pd.DataFrame(columns = ['a','b','c']) entry = {'a':'test', 'b':1, 'c':float(2)} df.loc[0] = ...
ThatNewGuy's user avatar
0 votes
1 answer
576 views

I'm trying to find data in my dataframe which doesn't include this string [] In my dataset I have in column tags these values: I'm using following code but it doesn't work as I expect conversion_rate ...
Tomas Kostovcik's user avatar
1 vote
3 answers
1k views

I'm trying to set up a script which will generate comments for student reports. To set up a general template, I'm using a marks table which has their percentage scores. I'm having trouble using an f ...
Liam Graneri's user avatar
5 votes
1 answer
4k views

trying to sum rows for specific columns in pandas. have: df = name age gender sales commissions joe 25 m 100 10 jane 55 f 40 4 want: df = name age gender ...
nia4life's user avatar
  • 373
1 vote
1 answer
68 views

This is a continuation of a previous question. Now, I want to have these occurrences grouped by year so that the output would become something like: Combo Occurrence (2017) Occurrence (...
JeppeBay's user avatar
  • 141
-1 votes
1 answer
226 views

Can someone please tell me what the right syntax would be to do the following: dfpollution3.loc(max(dfpollution3.index),'newhospinextday') = 10 I get the following error: dfpollution3.loc(max(...
Ludo915's user avatar
  • 23
2 votes
1 answer
2k views

I am trying to filter my dataframe on multiple conditions using loc The data is coming from an Excel file that I imported into the dataframe using df = pd.read_csv() Here is sample structure from the ...
ghalvorson's user avatar
1 vote
1 answer
697 views

Working with pandas dataframe suppose i have data frame with similar structure as following: import pandas as pd a_choise = ["True", "False", "False", "False", &...
Abdelsabour's user avatar
1 vote
0 answers
449 views

I everyone, I've gotten the dreaded "A value is trying to be set on a copy of a slice from a DataFrame." error. I saw a possible solution here How to deal with SettingWithCopyWarning in ...
Celia's user avatar
  • 45
1 vote
3 answers
111 views

So this is a common question but I cant find an answer that fits this particular scenario. So I have a Dataframe with columns for genres eg "Drama, Western" and one hot encoded versions of ...
Digital Moniker's user avatar
0 votes
1 answer
521 views

This code line: gen_histogram = df.loc[1, ['lymphoid_neoplasm']] gives a error like KeyError: "None of [Index(['lymphoid_neoplasm'], dtype='object')] are in the [index]" All code: import ...
icv's user avatar
  • 1
1 vote
1 answer
133 views

I am looking for help on how to simplify my code. The DataFrame is >100k rows and could have multiple columns that contain a mix of strings and integers. Here is an example df: data = { "...
thejahcoop's user avatar
1 vote
0 answers
1k views

I have a problem with 'loc' and'iloc' .So I have a list and a data frame, I want to check if the data in list and date in data frame of a column is matching. if matching I need to copy it to a new ...
Rapooram 's user avatar
1 vote
1 answer
136 views

I have this dataframe: Column Non-Null Dtype 0 nombre 74 non-null object 1 fabricante - 74 non-null - object 2 calorias -74 ...
vladimir's user avatar
1 vote
1 answer
150 views

I am trying to loop through a DF column and get just the URL key from a column of strings. I have printed every stage of this loop and it works correctly. However when printing the DF after the loop ...
Kyle Shaffer's user avatar
0 votes
2 answers
398 views

I have this code to replace ages from numeric data to categorical data. I'm trying to do it that way, but it's not working. Can anybody help me? for df in treino_teste: df.loc[df['Age'] <= 13, '...
Henrique Krupck Secchi's user avatar
2 votes
1 answer
185 views

I'm working with this dataframe: P Q date 0 [2, 3, 4] [2, 2] 2019-3-18 1 [fff] [2] 2019-3-18 2 [] [2] 2019-10-24 3 [4, 5] [2] 2019-1-1 I can ...
Germán García Aguilar's user avatar
0 votes
1 answer
347 views

import pandas as pd data = {'name': ['HelloWorld', 'ByeWorld'], 'physics': [22, 33], 'chemistry': [44, 55]} a = pd.DataFrame(data) b = a.loc[a['name'] == 'Hello'] print(b) This ...
filtertips's user avatar
0 votes
0 answers
43 views

I have some code which looks for the full name of a browser in a column and where found overwrites with a short name. this is to allow simplified filtering without version numbers in visualisations. ...
MizzH's user avatar
  • 13
0 votes
2 answers
46 views

So my dataset is survey data, where each row shows a question and a unique respondent's numeric response to that question. Unfortunately, the scale was backwards for some question (aka 1s should be 4s ...
Colin Sorensen's user avatar

1 2 3
4
5
8