Pandas operation memorandum
I don't want to stumble at the same place, so I write a memo.
Ignore index and add column
df_1 = df_1.reset_index(drop=True)
df_2['xxx'] = df_1['xxx']
- Basically, only the second line is enough
- The first line is required in the following cases
- If index is not a serial number from 0
- Unexpected sorting may have occurred
- If there are duplicate indexes
- Duplicate index data is duplicated
Reason
- To combine using the index of df_1 as a key
Forced column name conversion
.py
df.columns = ['aaa', 'bbb', 'ccc', ...]