Let us create a pandas dataframe
with two columns:
lendf = pd.read_csv('/git/opencv-related/experiments/audio_and_text_files_lens.csv',
names=['path','duration'])
Here is the default numerically incrementing index
:
Let's change the index
to allow searching by the path
attribute:
lendf.set_index(['path'])
But the index
did not change??
How about invoking reindex()
?
lendf.reindex()
Still no change!
Note that I had been referencing the source code sphinx https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.set_index.html : here is an excerpt:
So then what am I misunderstanding about pandas
indexing - and how should the search/indexing by path
be set up?
You need to pass inplace=True
otherwise set_index
will return a new dataframe not alter the existing one
lendf.set_index(['path'], inplace=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.