PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 28, 2022

[FIXED] How can I import total Ordner

 August 28, 2022     csv, import, python     No comments   

Issue

I have path '/Users/OneDrive/Desktop/Data_CSV' in this path I have 3 folders in each folder 5 folders in each folder 12 csv data.

how can i import total?

what I can. I can only import a whole folder, but folders in folders in folders I can not do well.

this code is for one Ordner:

import glob
import os   
import pandas as pd 

directory = '/Users/OneDrive/Desktop/Data_CSV'

all_files = glob.glob(os.path.join(directory, "*.csv"))



your_list = [ ]
for filename in all_files:
    dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
    your_list.append(dataframe)
    print(dataframe)

Solution

You can iterate through the folders recursively

import glob

# root_dir needs a trailing slash (i.e. /root/dir/)
for filename in glob.iglob(directory + '**/*.txt', recursive=True):
     dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
     your_list.append(dataframe)


Answered By - Himanshuman
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing