Questions tagged [pandas-loc]

For questions about the [pandas] loc indexer. This tag should only be used for questions primarily about pandas loc or the behavior of this indexer. Be sure to also include the [pandas] tag on your question.

The pandas loc indexer allows for label based data selection from pandas DataFrames on multiple axes simultaneously.

It is primarily used in data Selection by label and Setting data at specific locations in a pandas DataFrame.

There are loc indexers for both DataFrames and Series.

381 questions
0
votes
1 answer

Loc filter and exclude null values

1. vat.loc[(vat['Sum of VAT'].isin([np.nan, 0])) & 2. (vat['Comment'] == "Transactions 0DKK") & 3. (vat['Type'].isin(['Bill', 'Bill Credit'])) & 4. (vat['Maximum of Linked Invoice'].notnull()), 'Comment'] = 'Linked invoice' 5.…
Darko86
  • 65
  • 1
  • 4
0
votes
1 answer

Pandas - .loc / lambda / time series

I did a web scraping which returns a table of port congestion. So each row represents a ship and its days of arrival, berthing and departure. Link for data source I'd like my code only to retrieve data of the interval from yesterday up to the 7…
0
votes
1 answer

Pandas filter with Loc but exclude values in rows

1vat.loc[(vat['Sum of VAT'].isin([np.nan, 0])) & 2 (vat['Comment'] == 'Transactions 0DKK') & 3 (vat['Memo (Main)'] != '- None -'), 'Comment'] = 'Travel bill' 4vat[vat["Comment"] == "Travel bill"] I have a problem with line 3. It seems…
Darko86
  • 65
  • 1
  • 4
0
votes
1 answer

Looking up a column value based on two column values in a pandas dataframe

I need to get the value from a column based on two specific column values. Example Dataframe: Charge Code Billing Number Date 0 1250-001 500220 1/2/20 1 1230-002 300220 2/6/20 2 1250-001 500320 …
codeblue
  • 63
  • 1
  • 8
0
votes
1 answer

How to insert a certain value to rows in pandas

I want to change a column from str to float. The column has now numbers with suffix 'M' or 'K' which I want to remove and keep only the number, and a string which I want to replace to 0. 1) In order to remove the chars M and K, I used…
Eve
  • 1
0
votes
3 answers

what is the pandas ix or iloc multiple condition syntax

Processing the government Office of Foreign Assets Controls (OFAC) list https://www.treasury.gov/ofac/downloads/sdn.csv The 2nd column (the number starting from 0) suggests if this row is an individual, business (-0-), airplane, or vessels…
Chubaka
  • 2,933
  • 7
  • 43
  • 58
0
votes
1 answer

Update Dataframe Column Value based on another column value being null using df.loc[]

I am aware that similar questions have been asked before but none of the answer cater to my specific case, see below: dummy_1 dummy_2 dummy_3 output 1 Yes Yes 2 3 Yes Yes 4 Yes I update the output…
user8478307
0
votes
2 answers

itterows updating issues for pandas

I have a dataset: id name m 0 1 mina 0 1 1 sara 0 2 2 travi 0 3 3 caty 0 5 4 el 0 6 6 tom 0 I wrote the following code for changing my dataframe for index, row in df.iterrows(): if(row['m']==0): …
ash
  • 79
  • 6
0
votes
1 answer

loc Funktion next value

I have a little problem with the .loc function. Here is the code: date = df.loc [df ['date'] == d] .index [0] d is a specific date (e.g. 21.11.2019) The problem is that the weekend can take days. In the dataframe in the column date there are no…
pythoo
  • 27
  • 7
0
votes
1 answer

How to select rows based on two column that must contain specific value?

I have a dataset with a lot of incorrect duplicates on a certain field, in my reproducible example there are duplicates in serial with different color and shape. I have the actual dataframe with the correct color and shape to serial mapped, and need…
geistmate
  • 525
  • 2
  • 5
  • 14
0
votes
1 answer

Count will not work for unique elements in my dataframe, only when repeated

I want to count the number of occurences in a dataframe, and I need to do it using the following function: for x in homicides_prec.reset_index().DATE.drop_duplicates(): count= homicides_prec.loc[x]['VICTIM_AGE'].count() print(count) However, this…
0
votes
1 answer

Removing duplicate data from pandas Dataframe

I am trying to retrive data every few hours and since the data will have a lot of duplicate data I will remove all the duplicate data which has the same date and keep the first instance. Here is my code to do this: import pandas as pd import…
user8596384
0
votes
0 answers

Python .loc within function VS outside the function

I have a quite specific question pertaining to how ".loc" function works on the backend when 1. applied directly to a daraframe (ex. df.loc[]) as opposed to being used in a defined method and then applied using "df.apply()". Here is the MultiIndex…
0
votes
1 answer

Drop rows from dataframe where problematic values are in separate list

I have a list of problematic rows where there is a unique identifier, all of which I want to remove from a dataframe. I've tried to use loc to index them, as follows: df.loc[df['GUID'] != toDel['GUID']] where df is 5063 row x 28 cols and…
galal27
  • 51
  • 1
  • 8
0
votes
0 answers

Why doesn't df.loc work properly for my DataFrame?

df.loc function doesn't seem to work properly for my DataFrame. I think it has something to do with the reader library I have chosen. Since I'm importing a .sav file b' ' prefix appears in every column, so in the name column, df['name'] b'Steve'…
user11357465