During the panda data operation, two tricks appear during expansion:
Using data_PD. Append(), when expanding data in rows, the row names need to be the same in order to realize automatic expansion and use data_ PD. Columns = [], when modifying the row name, slicing is not allowed, and only a list can be created according to the original data length for assignment modification
# Iterate through different individual data and perform data stitching
response_pd = pd.DataFrame() # Create an empty panda
for ii in range(100, 106):
sub = 'Sub%d'%ii
index = np.where((np.array(filter_pd[sub+'_fg'])!=-100)&
(np.array(filter_pd[sub+'_frt'])!=-100))[0]
ii=ii-100
col_index =list(range(2, 7))+list(range(8, 20))+[23+ii*4,21+ii*4,22+ii*4]
# Filter the data in the specified row
temp_pd=filter_pd.iloc[index].iloc[:, col_index]
## Modify the row names, note that the slicing operation is not allowed here, only the original data length, create a list to assign values
temp_pd.columns = list(temp_pd.columns)[:-3]+['first glance', 'first RT', 'last RT']
# Expand the rows, note that you need the same row name to expand the data for the corresponding row
response_pd = response_pd.append(temp_pd,
ignore_index=True)
print('table shape',response_pd.shape)
Read More:
- Solve the error of panda index unalignable Boolean series provided as indexer
- [Solved] ValueError: row index was 65536, not allowed by .xls format
- Python: Panda scramble data
- [Solved] MindSpore Error: “operation does not support the type kMetaTypeNone“
- [Solved] This error might have occurred since this system does not have Windows Long Path support enabled.
- [Solved] C error: expected 1 fields in line 3, saw 2 processing method
- How does Python output colored fonts in the CMD command line window
- How to Fix Errors encountered in executing Python scripts with command line parameters
- Import * has a red wavy line, but the operation does not report an error
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- Python Valueerror: cannot index with vector containing Na / Nan values
- [resolution] str.contains() problem] valueerror: cannot index with vector containing Na/Nan values
- IndexError: list index out of range [How to Solve]
- [Solved] RuntimeError: scatter(): Expected dtype int64 for index
- Python: How to Set Line breaks and tabs for Strings
- Python reads excel and stores it in the list according to the header hash copy.deepcopy
- Pandas Read csv Error tokenizing data. C error: Expected 18 fields in line 173315, saw 20
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- [Solved] Pylint Warning: An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)