Python Pandas to create a DataFrame from CSV file
kw.csv
kw.py
Output
kodingwindow@kw:~$ python3 kw.py account_no name city dob bank amount 0 25622348989 James Moore Phoenix 1985-05-26 Barclays 5000 1 25622348990 Donald Taylor Irvine 1990-08-20 Citi 7000 2 25622348991 Edward Parkar Irvine 1994-01-29 ICICI 95000 3 25622348992 Ryan Bakshi Mumbai 1982-01-14 Citi 50000 4 25622348993 Marie Peters Ribe 1967-01-05 DZBank 12250 5 25622348994 Aanya Delhi 1975-08-18 SBI 105000 6 25622348995 James Moore NaN 1978-06-26 Citi 97800
Python Pandas to create a DataFrame from Excel spreadsheet
kw.xlsx
+------------+---------------+---------+------------+----------+--------+ | account_no | name | city | dob | bank | amount | +------------+---------------+---------+------------+----------+--------+ | 2562348989 | James Moore | Phoenix | 1985-05-26 | Barclays | 5000 | | 2562348990 | Donald Taylor | Irvine | 1990-08-20 | Citi | 7000 | | 2562348991 | Edward Parkar | Irvine | 1994-01-29 | ICICI | 95000 | | 2562348992 | Ryan Bakshi | Mumbai | 1982-01-14 | Citi | 50000 | | 2562348993 | Marie Peters | Ribe | 1967-01-05 | DZ Bank | 12250 | | 2562348994 | Aanya | Delhi | 1975-08-18 | SBI | 105000 | | 2562348995 | James Moore | | 1978-06-26 | Citi | 97800 | +------------+---------------+---------+------------+----------+--------+
kw.py
Output
kodingwindow@kw:~$ python3 kw.py account_no name city dob bank amount 0 25622348989 James Moore Phoenix 1985-05-26 Barclays 5000 1 25622348990 Donald Taylor Irvine 1990-08-20 Citi 7000 2 25622348991 Edward Parkar Irvine 1994-01-29 ICICI 95000 3 25622348992 Ryan Bakshi Mumbai 1982-01-14 Citi 50000 4 25622348993 Marie Peters Ribe 1967-01-05 DZBank 12250 5 25622348994 Aanya Delhi 1975-08-18 SBI 105000 6 25622348995 James Moore NaN 1978-06-26 Citi 97800
Python Pandas to create a DataFrame from Dictionary
kw.py
Output
kodingwindow@kw:~$ python3 kw.py account_no name city dob bank amount 0 25622348989 James Moore Phoenix 1985-05-26 Barclays 5000 1 25622348990 Donald Taylor Irvine 1990-08-20 Citi 7000 2 25622348991 Edward Parkar Irvine 1994-01-29 ICICI 95000 3 25622348992 Ryan Bakshi Mumbai 1982-01-14 Citi 50000 4 25622348993 Marie Peters Ribe 1967-01-05 DZBank 12250 5 25622348994 Aanya Delhi 1975-08-18 SBI 105000 6 25622348995 James Moore NaN 1978-06-26 Citi 97800
Python Pandas to create a DataFrame from List of Tuples
kw.py
Output
kodingwindow@kw:~$ python3 kw.py account_no name city dob bank amount 0 25622348989 James Moore Phoenix 1985-05-26 Barclays 5000 1 25622348990 Donald Taylor Irvine 1990-08-20 Citi 7000 2 25622348991 Edward Parkar Irvine 1994-01-29 ICICI 95000 3 25622348992 Ryan Bakshi Mumbai 1982-01-14 Citi 50000 4 25622348993 Marie Peters Ribe 1967-01-05 DZBank 12250 5 25622348994 Aanya Delhi 1975-08-18 SBI 105000 6 25622348995 James Moore NaN 1978-06-26 Citi 97800
What Next?
Python Pandas to extract rows and columns from a DataFrame
Python Pandas to index and sort a DataFrame
Python Pandas to fill and drop missing data in a DataFrame
Advertisement