Skip to content

Commit b18cc57

Browse files
author
Steve Baskauf
committed
add video for loading spreadsheets into a DataFrame
1 parent 98bd5f7 commit b18cc57

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

script/codegraf/ees3/index.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,47 @@ states_df.loc['PA', 'population']
180180

181181
The resulting object has the type of the cell value.
182182

183-
184183
---
185184

185+
# Loading a DataFrame from a file
186+
187+
One nice thing about loading spreadsheet data into a pandas DataFrame is that the file can come either from your local file directory or from a URL. The same function can be used for either data source.
188+
189+
## Loading a spreadsheet via a URL (3m02s)
190+
191+
Functions for reading and writing from spreadsheets to pandas DataFrames:
192+
193+
`pd.read_csv()` read from a CSV file into a data frame.
194+
195+
`pd.to_csv()` write from a data frame to a CSV file.
196+
197+
`pd.read_excel()` read from an Excel file into a data frame.
198+
199+
`pd.to_excel()` write from a data frame to an Excel file.
200+
201+
For details about reading from particular sheets in an Excel file, delimiters other than commas, etc. see the [pandas User Guide](https://pandas.pydata.org/docs/user_guide/io.html) and [this Stack Overflow post](https://stackoverflow.com/questions/26521266/using-pandas-to-pd-read-excel-for-multiple-worksheets-of-the-same-workbook).
202+
203+
<iframe width="1120" height="630" src="https://www.youtube.com/embed/JVwKj7H8QU0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
204+
205+
Note: when loading files via a URL, be sure that the URL delivers the raw file, not an HTML representation of the file.
206+
207+
**Examining the DataFrame**
208+
209+
Use the `.head()` method to view only the first few lines of a DataFrame (default is 5 if `number_of_lines` argument omitted):
210+
```
211+
dataframe.head(number_of_lines)
212+
```
213+
214+
The `.tail()` method is similar, but shows the last few lines of a DataFrame
215+
216+
The `.shape` attribute returns a tuple of the number of rows and number of columns.
217+
218+
The `.columns` attribute returns the column names as a pandas Index object. Use the `list()` function to convert into a simple Python list.
219+
220+
The `.index` returns the row label indices as a pandas Index object. Use the `list()` function to convert into a simple Python list.
221+
222+
----
223+
186224
# Loops
187225

188226
## for loops (5m46s)

0 commit comments

Comments
 (0)