Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
995 views

I have a DataFrame, D1 that looks as follows: close Date Symbol ICO_to 2.71 6/12/2017 18:00 MYST 5/30/2017 2.18 6/13/2017 18:00 MYST 5/30/2017 2.1 6/14/2017 18:00 MYST 5/30/2017 2.17 6/15/...
Cole Starbuck's user avatar
2 votes
1 answer
1k views

I have a DataFrame, D1: Date Symbol ICO_to 5/28/2017 18:00 MYST 5/30/2017 5/29/2017 18:00 MYST 5/30/2017 5/30/2017 18:00 MYST 5/30/2017 6/1/2017 18:00 MYST 5/30/2017 6/2/...
Cole Starbuck's user avatar
1 vote
2 answers
197 views

I have written the code like below to filter out the records from the column named 'Document Type' which contains around 25 categorical values. salesdf.loc[(salesdf['Document type'] != 'AVC') & (...
vishnu prashanth's user avatar
0 votes
1 answer
171 views

Below is an existing df data = np.array([['','Market','Product Code','Week','Sales','Units'], ['Total Customers',123,1,500,400], ['Total Customers',123,2,400,320], ...
jwlon81's user avatar
  • 359
2 votes
2 answers
4k views

I want to find the first value after each row that meets a certain criteria. So for example I want to find the first rate/value (not necessarily the first row after) after the current row that ...
Liam Hanninen's user avatar
4 votes
1 answer
16k views

I´m tying to loc a dataframe with 2 columns parameters: if I do paises_cpm = df.loc[a]is working but if I do paises_cpm = df.loc[a,b] I receive an error: IndexingError: Unalignable boolean Series ...
Martin Bouhier's user avatar
13 votes
4 answers
16k views

I have a table df a b c 1 x y [x] 2 x z [c,d] 3 x t [e,f,g] Just wondering how to select the row using the length of c column such as df.loc[len(df.c) >1] I know ...
Kevin's user avatar
  • 597
5 votes
1 answer
9k views

Consider the data frame df = pd.DataFrame(numpy.random.randint(0,10,size=(5, 4)), columns=list('ABCD')) df A B C D 0 5 8 0 4 1 7 4 9 0 2 8 1 1 8 3 2 7 6 6 4 4 3 3 0 I would ...
Kenny's user avatar
  • 2,022
0 votes
1 answer
76 views

I would like to create a new column under the following condition: So basically I have two column Majoy car and Major housetype. I would let all the 'nocar' within Majoy car AND 'Rented' within Major ...
Guo Yijin's user avatar
2 votes
3 answers
65 views

if I have a date frame like this: N EG_00_04 NEG_04_08 NEG_08_12 NEG_12_16 NEG_16_20 NEG_20_24 \ datum_von 2017-10-12 ...
may's user avatar
  • 1,205
5 votes
1 answer
2k views

How to apply pandas.to_numeric to a subset of DataFrame selected using .loc[]? E.g. consider this DataFrame: df = pd.DataFrame(index=pd.Index([1, 2, 3])) df['X'] = ['a', 'a', 'b'] df['Y'] = [1, 2, 3] ...
Krzysztof Arendt's user avatar
1 vote
3 answers
69 views

I am new to pandas and hence please treat this question with patience I have a Df with year, state and population data collected over many years and across many states I want to find the max pop ...
Padma's user avatar
  • 37
30 votes
2 answers
5k views

So .loc and .iloc are not your typical functions. They somehow use [ and ] to surround the arguments so that it is comparable to normal array indexing. However, I have never seen this in another ...
Conner Phillips's user avatar
1 vote
1 answer
1k views

I genuinely don't get why it returns NaN I have a df and i need to create one more column based on other columns values, this method always worked. train.loc[(train.region == 'Latin America') & (...
Khrystyna Kosenko's user avatar
71 votes
1 answer
210k views

This should be incredibly easy, but I can't get it to work. I want to filter my dataset on two or more values. #this works, when I filter for one value df.loc[df['channel'] == 'sale'] #if I have ...
jeangelj's user avatar
  • 4,528
1 vote
3 answers
990 views

I have a dataframe with 7 columns, as follows: Bank Name | Number | Firstname | Lastname | ID | Date1 | Date2 B1 | 1 | ABC | EFG | 12 | Somedate | Somedate B2 | 2 ...
akrama81's user avatar
  • 351
2 votes
1 answer
541 views

df[['gc_lat', 'gc_lng']] = df[['gc_lat', 'gc_lng']].apply(pd.to_numeric, errors='ignore') df_realty[['lat', 'lng']] = df_realty[['lat', 'lng']].apply(pd.to_numeric, errors='ignore') for index, row in ...
vazhega's user avatar
  • 31
2 votes
1 answer
17k views

I am fairly new to Python, especially pandas. I have a DataFrame called KeyRow which is from a bigger df: KeyRow=df.loc[df['Order'] == UniqueOrderName[i]] Then I make a nested loop for i in range (0,...
Questions's user avatar
  • 137
0 votes
0 answers
150 views

I have been searching for a way to replace itterrows with vectorization and coming up blank. I have this code which i believe to be working correctly using itterows which is taking forever. sm_state ...
3ricVos's user avatar
15 votes
3 answers
16k views

I can create a new row in a dataframe using .loc(): >>> df = pd.DataFrame({'a':[10, 20], 'b':[100,200]}, index='1 2'.split()) >>> df a b 1 10 100 2 20 200 >>> df....
Zhang18's user avatar
  • 4,950
2 votes
2 answers
11k views

I want to ask you, How to select rows that have the same index number in a DataFrame. Example: df= A, B, C, 0 1. 2. 1. 1 2. 2. 2. 2 2. 2. 2. 3 3. 3. 4. A, B, C, 0 1. 2. 1. 1 2. 2. 2. 2 2. 2. ...
Jonathan Pacheco's user avatar
1 vote
3 answers
3k views

I have a dataframe df with age and I am working on categorizing the file into age groups with 0s and 1s. df: User_ID | Age 35435 22 45345 36 63456 18 63523 55 I tried the ...
jeangelj's user avatar
  • 4,528
4 votes
1 answer
2k views

Suppose I have two dataframes; one holds transactions, trans and the other holds product information, prod, and I want to join the product prices, the variable price, on to the transaction data frame, ...
Superpronker's user avatar
1 vote
1 answer
651 views

This might be a rather useless question but I would like to learn how to do .loc for same column sliced by rows at same time. Lets imagine I have this df: k1 = pd.DataFrame([1,2,3,4]) k2 = pd....
Borja_042's user avatar
  • 1,071
8 votes
1 answer
37k views

I tried to solve the required task with the following code line: df['Age'][np.isnan(df["Age"])] = rand1 But this raises a "SettingWithCopyWarning" and I think locating the Nan values in the dataframe ...
ErnieandBert's user avatar
1 vote
1 answer
10k views

Here is a head() of my DataFrame df: Temperature DewPoint Pressure Date 2010-01-01 00:00:00 46.2 37.5 1.0 ...
Steve's user avatar
  • 261
4 votes
1 answer
5k views

I am experimenting with the Pandas loc() method, used with boolean arrays as arguments. I created a small dataframe to play with: col1 col2 col3 col4 0 a 1 2 3 1 ...
im7's user avatar
  • 683
3 votes
1 answer
3k views

I am new to pandas. I want to add a new column to a pandas dataframe df and assign "Start" to every odd row and "Stop" to every even row. However, when I do df.iloc[1::2, :] = "Start", I am ...
sudonym's user avatar
  • 4,038
0 votes
1 answer
3k views

I am trying to replace all values in a pandas dataframe column df.column_A if they fall within the range of 1 to 10. However, when I do: df.loc[(1 < df.column_A < 10), "Column_A"] = 1 ...
sudonym's user avatar
  • 4,038
134 votes
3 answers
65k views

Why do we use loc for pandas dataframes? it seems the following code with or without using loc both compiles and runs at a similar speed: %timeit df_user1 = df.loc[df.user_id=='5561'] 100 loops, best ...
Runner Bean's user avatar
  • 5,241
0 votes
0 answers
520 views

I encounter a strange problem in pretty big piece of code. Normally, I use .loc to change particular items in a certain column within a loop while using a row_index variable as help. Lets assume to ...
Ripple10247's user avatar
2 votes
1 answer
66 views

I need to update a panel slice with some values retreated from a dataframe. Even if I don't get back any error it doesn't work. What it's wrong ? df = pd.DataFrame(np.random.rand(10, 4), ...
Cursore's user avatar
  • 33
3 votes
2 answers
14k views

I am trying to subtract one row from another in a Pandas DataFrame. I have multiple descriptor columns preceding one numerical column, forcing me to set the index of the DataFrame on the two ...
KidMcC's user avatar
  • 486
0 votes
0 answers
148 views

I have a dataframe df which looks like this: Order Type Quantity 2015-04-30 Buy 200 2015-05-06 Buy 168 2015-05-08 Sell 368 2015-06-04 Buy ...
ralphW's user avatar
  • 1
1 vote
1 answer
524 views

I am looking to manipulate a large set of data based on a couple of conditionals. One is based on the same row whereas the other is based on a cell from a different row. For example i have a df like ...
Mad_Hatter's user avatar
19 votes
3 answers
52k views

I have a pandas dataframe (df) with the column structure : month a b c d this dataframe has data for say Jan, Feb, Mar, Apr. A,B,C,D are numeric columns. For the month of Feb , I want to recalculate ...
Data Enthusiast's user avatar
2 votes
1 answer
4k views

I have the multilevel dataframe that looks like: date_time name note value list index 1 0 2015-05-22 05:37:59 Tom 129 ...
user avatar
0 votes
1 answer
1k views

I have a potential pandas bug, or maybe I've just been staring at this too long. I have not had issues using xs on a multi index before. Code is bellow and I've verified that the error occurs on both ...
htln's user avatar
  • 1
1001 votes
7 answers
884k views

Can someone explain how these two methods of slicing are different? I've seen the docs and I've seen previous similar questions (1, 2), but I still find myself unable to understand how they are ...
AZhao's user avatar
  • 14.5k
0 votes
1 answer
320 views

There is a statement in my code that goes: df.loc[i] = [df.iloc[0][0], i, np.nan] where i is an iteration variable that I used in the for loop that this statement is residing in,np is my imported ...
AKKO's user avatar
  • 1,091
3 votes
2 answers
3k views

I have data similar to this post: pandas: Filling missing values within a group That is, I have data in a number of observation sessions, and there is a focal individual for each session. That focal ...
M.A.Kline's user avatar
  • 1,727

1
4 5 6 7
8