logo
down
shadow

Pandas giving IndexError on one dataframe but not on another similar dataframe


Pandas giving IndexError on one dataframe but not on another similar dataframe

Content Index :

Pandas giving IndexError on one dataframe but not on another similar dataframe
Tag : python , By : ikey
Date : January 11 2021, 05:14 PM

hop of those help? I'm getting the error:
DATE,x,y
123,5,7
Date,X,Y
1991-07-09,123,123

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

IndexError when trying to perform ffill() on pandas dataframe


Tag : python , By : Kristian Hofslaeter
Date : March 29 2020, 07:55 AM
seems to work fine Your error is that you're overwriting your df variable with a single column from a previous value.
df = df["VWPfgbl"].ffill()
df = df["VWPfgbm"].ffill()
df = df["VWPfgbs"].ffill()
df["VWPfgbl"] = df["VWPfgbl"].ffill()
df["VWPfgbm"] = df["VWPfgbm"].ffill()
df["VWPfgbs"] = df["VWPfgbs"].ffill()

Pandas IndexError for large dataframe


Tag : python , By : Barry
Date : March 29 2020, 07:55 AM
I hope this helps you . This is very weird indeed.
You can use something like this as a workaround:
vec = pd.merge(vec, pd.DataFrame([0, 0], columns=["new"]), right_index=True, left_index=True)  # Optional: pass copy=False
df = pd.DataFrame(np.zeros((2, 2546540)))
df[2546540] = 0
df["blah"] = 0
TypeError: unorderable types: numpy.ndarray() < str()
df = pd.DataFrame(np.zeros((2, 200)))
df[200] = 0
   0    1    2    3    4    5    6    7    8    9   ...   191  192  193  194  0    0    0    0    0    0    0    0    0    0    0 ...     0    0    0    0   
1    0    0    0    0    0    0    0    0    0    0 ...     0    0    0    0   

   195  196  197  198  199  200  
0    0    0    0    0    0    0  
1    0    0    0    0    0    0  

[2 rows x 201 columns]

pandas: IndexError while iterating over DataFrame column


Tag : python , By : user134570
Date : March 29 2020, 07:55 AM
I hope this helps . So, I have this DataFrame and I'm trying to iterate over one of its columns:'Party', and it looks like this: , Setup
df=pd.DataFrame({'Party': {0: 'Democratic', 1: 'Republican', 2: 'Republican'},
 'President': {0: 'WoodrowWilson', 1: 'WarrenG.Harding', 2: 'WarrenG.Harding'},
 'Value': {0: np.nan, 1: 0.12717200000000001, 2: 0.21738600000000002},
 'Year': {0: 1920, 1: 1921, 2: 1922}})

df
Out[1243]: 
        Party        President     Value  Year
0  Democratic    WoodrowWilson       NaN  1920
1  Republican  WarrenG.Harding  0.127172  1921
2  Republican  WarrenG.Harding  0.217386  1922

#you can do this without a loop using groupby.
df_Democrat = df.rename(columns={'Value':'Return'}).groupby('Party')['Party','Year','Return'].get_group('Democratic')
Out[1238]: 
        Party  Year  Return
0  Democratic  1920     NaN

df_Republican  = df.rename(columns={'Value':'Return'}).groupby('Party')['Party','Year','Return'].get_group('Republican')
Out[1239]: 
        Party  Year    Return
1  Republican  1921  0.127172
2  Republican  1922  0.217386

Fill a column in the dataframe based on similar values from another dataframe in pandas


Tag : python , By : arbeitandy
Date : March 29 2020, 07:55 AM
this one helps. I think need map by Series created by set_index - if some value not match get NaNs:
df2['year'] = df2['№'].map(df1.set_index('№')['year'])
df2['year'] = df2['№'].map(df1.set_index('№')['year']).combine_first(df2['year'])

PYTHON Pandas Dataframe SENSEI DataFrame Strange IndexError in the iloc[] code for copying rows from one dataframe to an


Tag : python-3.x , By : orneka
Date : March 29 2020, 07:55 AM
will help you There is no real need for you to do this by iterating over each line. You can just create a new sensei5 object by using boolean indexing on the original dataframe as follows:
import pandas as pd
year = ['2017','2010','2015','2014','2013', '2013','2011','2012','2014','2010']
master = ['foo', 'bar', 'foo1', 'bar1', 'foo2', 'bar2', 'foo3', 'bar3', 'foo4', 'bar4']

sensei = pd.DataFrame({'year' : year, 'master' : master})
sensei5 = sensei[2017 - sensei['year'].astype(int) <=5]
  master  year
0    foo  2017
2   foo1  2015
3   bar1  2014
4   foo2  2013
5   bar2  2013
7   bar3  2012
8   foo4  2014
newSensei5 = pd.DataFrame(columns = sensei.columns)
for row in range(len(sensei)):
    if int(sensei.loc[row, 'year']) >=2012:
        newSensei5.loc[row, :] = sensei.loc[row, :]
In [23]: newSensei5
Out[23]:
  master  year
0    foo  2017
2   foo1  2015
3   bar1  2014
4   foo2  2013
5   bar2  2013
7   bar3  2012
8   foo4  2014
Columns = ["Date", "OpenScore", "HighScore", "LowScore", "CloseScore", "Adj CloseScore", "VolumeFights", "Year"]
a = [2000-11-23, 3837.110107,  3871.340088, 3826.419922,  3852.399902,  3852.399902 ,  12800 , "2000"]
b = [2017-11-24, 3860.520020,  3889.560059, 3856.580078,  3868.340088,  3868.340088 ,   12800, "2017"]

df = pd.DataFrame([a, b], columns = Columns)
df5 = df[2017 - df['Year'].astype(int) <=5]
Related Posts Related QUESTIONS :
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • Python: globals().items() iterations try to change a dict
  • Is it possible to specify starting values for each parameter (instead of bounds) for scipy's differential evolution?
  • why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?
  • MySQL multiple table UPDATE query using sqlalchemy core?
  • find if a semantic version is superset of of another version python
  • Type checking against dynamically created objects
  • Struggling with simple reverse function
  • Is there a function for finding the midpoint of n points on sklearn.neighbors.NearestNeighbors?
  • How to set max number of tweets to fetch
  • PYTHON 3.7.4 NOT USING SQLITE 3.29.0
  • How to replace Nan value with zeros in a numpy array?
  • How to speed up calculating variance among sparse matrix
  • cupy code is not fast enough compared with numpy
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com