Oct-25-2022, 11:22 AM
I want to move all columns to the right if my row starts with a letter, not a number.
Dataframe that I have:
"None of [Float64Index([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n ...\n nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],\n dtype='float64', length=200362)] are in the [index]"
What am I doing wrong?
Dataframe that I have:
var1 var2 var3 ... 9 3 3 4 4 3 ABC 5Dataframe that I want:
var1 var2 var3 ... 9 3 3 4 4 3 NaN ABC 5My code so far:
import pandas as pd df=pd.read_csv("input.csv", sep=",") mylist=['A', 'B', 'C', 'D'] # the alphabet list # identify rows that start with a letter m = df['NIF (EO)'].str.startswith(mylist) # define columns to correct cols = df.columns[1:] df.loc[m, cols] = df.loc[m, cols].shift(axis=1)However, in the last line of the code I am obtaining the error:
"None of [Float64Index([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n ...\n nan, nan, nan, nan, nan, nan, nan, nan, nan, nan],\n dtype='float64', length=200362)] are in the [index]"
What am I doing wrong?