I have a Pandas dataframe where indexes are numeric subject IDs of respondents, who participated in sociological test.
Basically, the question is two-fold.
a). How can I rename single duplicate index in Pandas DataFrame?
A portion of data looks like this (first column is index):
subject build gender_response
7 5.0.6.0 Female
5 5.0.6.0 Male
4 5.0.6.0 Male
3 5.0.6.0 Female
3 5.0.6.0 Female
1 5.0.6.0 Male
For example, I just need to reset one of the index ("3") to any other integer.
I have tried the major function from pandas documentation - http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.rename.html However, if I set parameter "Inplace" to True, nothing happens:
master.iloc[3].rename(120, inplace=True)
If I create a new variable and use same expression without this parameter, it return a Pandas.Series with new index:( But I need it to be applied to new dataframe.
master2 = master.iloc[3].rename(120)
b). How to make changes conditional to a value in other columns?
subject time Gender Age
7 12:30:10 Female 23
5 12:23:10 Male 18
4 12:22:17 Male 36
3 12:16:55 Female 45
3 12:16:16 Female 67
1 12:05:22 Male 28
For example, I have column "time" the test have been taken on. I tried to do it via Pandas apply function, something like:
time_point = pd.Timestamp(1/19/2017 12:16:55)
def filter_by_time(x):
if x[time] == Timestamp:
x.index.rename(120)
Applied it to the rows of dataframe.
Thoughts?