简体   繁体   中英

How to read data from multiple csv file and generate reports in THIS scenario?

Please Help me for this situation. We are building an project of an Attendance system in PYTHON with MySQL.

Now, we are marking the attendance of each person in the Database like:

ID    Name    Attend

1     ABC       1
2     BCA       0
3     CAB       0
4     CAA       1
5     NRC       1
6     NPR       1

Now, at the end of the day, automatically this attendance table will be exported into a CSV file with the name as the Date ie 12-12-19.xls

And daily the same practice will be repeated and the date ( name of the file ) will be changed so at the end of the month total 30/31 files (.xls) files will be there...

NOW ! THE QUESTION :

HOW TO FETCH ALL THE DATA FROM MULTIPLE 30/31 FILES AND GENERATE A CHART BASED ON THE ATTENDENCE ?

or is there another solution for this ?

Please Direct us to the solution.

Here is an alternative giving each date its own column:

import os
import pandas as pd

path = '/path/to/csv_files'
df = None
for filename in os.listdir(path):
    date = filename.split('.')[0]
    _df = pd.read_csv(f'{path}/{filename}', names=['ID', 'Name', date])
    if df is None:
        df = _df
    else:
        df[date] = _df[date]

df.plot()

I'd say:

import glob, os
import pandas as pd

os.chdir("/your_month_directory")
dfs = []
for file in glob.glob("*.csv"):
    dfs.append(pd.read_csv(file))

df = pd.concat(dfs)
df['Attend'].plot(kind='hist')

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM