Make a folder for each line in a csv with its corresponding name?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Make a folder for each line in a csv with its corresponding name?



csv has this structure:


col1
100
101
102
..
150



I want it to read each line and create a folder that there, will be created each folder for each line with the corresponding number as its name.
Also would be nice to store it in the Desktop.



Example:


New folder----100
----101
----102
..



What I tried:


import pandas as pd
import os
df = pd.read_csv(path)
for i in df:
os.mkdir(os.path.join())





for i in df["col1"]: os.mkdir(os.path.join(path, i)) ?
– Rakesh
Aug 6 at 7:23


for i in df["col1"]: os.mkdir(os.path.join(path, i))





pandas is overkill here. The csv module (included in standard distributions would be enough)
– Serge Ballesta
Aug 6 at 7:24




1 Answer
1



Try:


import pandas as pd
import os
path = "Your_Desktop_Path"
df = pd.read_csv(path)
for i in df["col1"].astype(str):
os.mkdir(os.path.join(path, i))



Or if you just have a single column.


import os

path = "Your_Desktop_Path"

with open(filename) as infile:
next(infile) #Skip Header
for line in infile:
os.mkdir(os.path.join(path, line.strip()))





TypeError: join() argument must be str or bytes, not 'int'
– user10185274
Aug 6 at 7:48





for i in df["col1"].astype(str):
– Rakesh
Aug 6 at 7:51


for i in df["col1"].astype(str):





You missed one detail: 'The main folder that will have these.' It has to create a folder that will store there all these folders.
– user10185274
Aug 6 at 7:54





Can you make it store it in one new folder, all these folders?
– user10185274
Aug 6 at 8:07






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard