michel
michel

Reputation: 284

pathlib joinpath in pandas 3.7

I am trying to join a relative path to an absolute one. I am confused as to this behavior:

from pathlib import Path
path = Path("/an/absolute/path/test")
path.joinpath("/../relative/path", "some_suffixes")

gives

PosixPath('/../relative/path/some_suffixes')

Why does this drop the first part of the path? What I expect is

PosixPath('/an/absolute/path/test/../relative/path/some_suffixes')

Upvotes: 0

Views: 399

Answers (1)

stavrosfil
stavrosfil

Reputation: 36

Seems like your problem is the relative path string you provide. You should remove the front forward slash and you should be good to go.

path.joinpath("../relative/path", "some_suffixes")

Upvotes: 1

Related Questions