@sidonduarte/

pandas_reading_csv

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# https://pt.stackoverflow.com/a/224069/7412
import pandas as pd
import io

# Simulando um CSV
s = '''
Mesa,Entrada,Saida,Conta
01,16:00,18:00,95.00
02,14:00,18:00,195.00
03,18:00,21:00,75.00
04,16:30,18:30,75.00
05,16:00,18:45,178.00
'''

# Lendo o csv 
df = pd.read_csv(io.StringIO(s), usecols=['Mesa', 'Entrada', 'Saida', 'Conta'])

# Imprimindo o resultado
print(df)

# Imprimindo coluna específica
print(df['Entrada'])

# Para iterar (navegar) nas linhas do dataframe:
for index, row in df.iterrows():
    print (row['Entrada'], row['Conta'])