I have a folder
JanuaryDataSentToResourcePro
that contain multiple .xlsx files. I want to iterate through folder and convert all of them into .csv and keep the same file name.For that I'm trying to implement glob, but getting an error:
TypeError: 'module' object is not callable
import glob excel_files = glob('*xlsx*') for excel in excel_files: out = excel.split('.')[0]+'.csv' df = pd.read_excel(r'''C:\Users\username\Documents\TestFolder\JanuaryDataSentToResourcePro\ResourceProDailyDataset_01_01_2018.xlsx''', 'ResourceProDailyDataset') df.to_csv(out)
I am new to python. Does it look right?
UPDATE:
import pandas as pd import glob excel_files = glob.glob("*.xlsx") for excel in excel_files: out = excel.split('.')[0]+'.csv' df = pd.read_excel(excel, 'ResourceProDailyDataset') df.to_csv(out)
But still not converting convert .xlsx to .csv
score:12
Accepted answer
The glob package should be used like:
import glob
f = glob.glob("*.xlsx")
The glob is not a method but glob.glob is.
========================================
import glob
excel_files = glob.glob('C:/Users/username/Documents/TestFolder/JanuaryDataSentToResourcePro/*.xlsx') # assume the path
for excel in excel_files:
out = excel.split('.')[0]+'.csv'
df = pd.read_excel(excel) # if only the first sheet is needed.
df.to_csv(out)
Credit To: stackoverflow.com
Related Query
- How to convert multiple .xlsx files in to .csv using pandas and globe
- How to import multiple csv files and concatenate into one DataFrame using pandas
- Convert multiple files from tsv to csv using pandas and glob
- Python using pandas to convert xlsx to csv file. How to delete index column?
- How do I append multiple CSV files using Pandas data structures in Python
- How to merge multiple CSV files using Python Pandas
- How to read CSV file with pandas containing quotes and using multiple seperators
- Pandas: how to merge horizontally multiple CSV (key,value) files and name `value` columns in the resulting DF using filenames
- How to read multiple csv files into pandas and output in one csv file
- How to take a PickleType data and convert to csv files in a folder using Python
- how to merge multiple csv files into 1 file based on column id using pandas
- How to sequentially create and save csv files using Pandas dataframe in python
- How to convert multiple .XLSX files in a diretory to CSV using pandas?
- How can I open multiple csv files in a folder, take the average of a column and save in a separate file using python?
- extract data from multiple csv files and prepare one dataframe using pandas
- How to rename multiple .Json files within a subfolder using python and pandas
- How to read faster multiple CSV files using Python pandas
- Import multiple csv files into pandas and concatenate into one DataFrame
- Read multiple csv files and Add filename as new column in pandas
- Read multiple parquet files in a folder and write to single csv file using python
- How to plot CSV data using matplotlib and pandas in python
- Pandas: import multiple csv files into dataframe using a loop and hierarchical indexing
- how to convert csv to dictionary using pandas
- Read multiple csv files into separate dataframes using pandas
- How to write CSV files into XLSX using Python Pandas?
- How to read multiple files and merge them into a single pandas data frame?
- How to read csv file with using pandas and cloud functions in GCP?
- How to import CSV file data into my database using pandas and pyodbc?
- creating one data frame using Pandas for multiple CSV files from many URL's
- Merging csv files using python and pandas (overlapping rows)
More Query from same tag
- Selecting all columns in DataFrame.set_index except one
- Changing the formatting of a datetime axis in matplotlib
- Reshape dataframe by string variable
- In Python-Pandas, How can I subset a dataframe by specific datetime index values?
- Reshape dataframe of list to another dataframe
- How can I transform a DataFrame so that the headers become column values?
- Fix ValueError: shapes (1,2) and (4,4) not aligned: 2 (dim 1) != 4 (dim 0) in python
- Can you install pandas in Google App Engine standard environment?
- Read rows in text file based on different column headers using Python
- Building another dataframe using minimun values of the columns using Pandas
- pandas multi-index how to mask the data by the second level
- Quantile threshold/filter within pandas groupby
- Convert Pandas df column list of strings to ints
- Python turning ints into floats (Postgres database)
- How to pick a subset of values with const difference from a list of values?