|
137 | 137 | na_values : scalar, str, list-like, or dict, default None
|
138 | 138 | Additional strings to recognize as NA/NaN. If dict passed, specific
|
139 | 139 | per-column NA values. By default the following values are interpreted
|
140 |
| - as NaN: '""" + fill("', '".join(sorted(_NA_VALUES)), 70) + """'. |
| 140 | + as NaN: '""" + fill("', '".join(sorted(_NA_VALUES)), 999) + """'. |
141 | 141 | keep_default_na : bool, default True
|
142 | 142 | If na_values are specified and keep_default_na is False the default NaN
|
143 | 143 | values are overridden, otherwise they're appended to.
|
|
160 | 160 | parsed : DataFrame or Dict of DataFrames
|
161 | 161 | DataFrame from the passed in Excel file. See notes in sheet_name
|
162 | 162 | argument for more information on when a Dict of Dataframes is returned.
|
| 163 | +
|
| 164 | +Examples |
| 165 | +-------- |
| 166 | +
|
| 167 | +An example DataFrame written to a local file |
| 168 | +
|
| 169 | +>>> df_out = pd.DataFrame([('string1', 1), |
| 170 | +... ('string2', 2), |
| 171 | +... ('string3', 3)], |
| 172 | +... columns=('Name', 'Value')) |
| 173 | +>>> df_out |
| 174 | + Name Value |
| 175 | +0 string1 1 |
| 176 | +1 string2 2 |
| 177 | +2 string3 3 |
| 178 | +>>> df_out.to_excel('tmp.xlsx') |
| 179 | +
|
| 180 | +The file can be read using the file name as string or an open file object: |
| 181 | +
|
| 182 | +>>> pd.read_excel('tmp.xlsx') |
| 183 | + Name Value |
| 184 | +0 string1 1 |
| 185 | +1 string2 2 |
| 186 | +2 string3 3 |
| 187 | +
|
| 188 | +>>> pd.read_excel(open('tmp.xlsx','rb')) |
| 189 | + Name Value |
| 190 | +0 string1 1 |
| 191 | +1 string2 2 |
| 192 | +2 string3 3 |
| 193 | +
|
| 194 | +Index and header can be specified via the `index_col` and `header` arguments |
| 195 | +
|
| 196 | +>>> pd.read_excel(open('tmp.xlsx','rb'), index_col=None, header=None) |
| 197 | + 0 1 2 |
| 198 | +0 NaN Name Value |
| 199 | +1 0.0 string1 1 |
| 200 | +2 1.0 string2 2 |
| 201 | +3 2.0 string3 3 |
| 202 | +
|
| 203 | +Column types are inferred but can be explicitly specified |
| 204 | +
|
| 205 | +>>> pd.read_excel(open('tmp.xlsx','rb'), dtype={'Name':str, 'Value':float}) |
| 206 | + Name Value |
| 207 | +0 string1 1.0 |
| 208 | +1 string2 2.0 |
| 209 | +2 string3 3.0 |
| 210 | +
|
| 211 | +True, False, and NA values, and thousands separators have defaults, |
| 212 | +but can be explicitly specified, too. Supply the values you would like |
| 213 | +as strings or lists of strings! |
| 214 | +
|
| 215 | +>>> pd.read_excel(open('tmp.xlsx','rb'), |
| 216 | +... true_values='2', |
| 217 | +... false_values='3', |
| 218 | +... na_values=['string1', 'string2'], |
| 219 | +... thousands=',') |
| 220 | + Name Value |
| 221 | +0 NaN 1 |
| 222 | +1 NaN 2 |
| 223 | +2 string3 3 |
| 224 | +
|
| 225 | +Comment lines in the excel input file can be skipped using the `comment` kwarg |
| 226 | +
|
| 227 | +>>> df = pd.DataFrame({'a': ['1', '#2'], 'b': ['2', '3']}) |
| 228 | +>>> df.to_excel('tmp.xlsx', index=False) |
| 229 | +>>> pd.read_excel('tmp.xlsx') |
| 230 | + a b |
| 231 | +0 1 2 |
| 232 | +1 #2 3 |
| 233 | +
|
| 234 | +>>> pd.read_excel('tmp.xlsx', comment='#') |
| 235 | + a b |
| 236 | +0 1 2 |
163 | 237 | """
|
164 | 238 |
|
165 | 239 |
|
|
0 commit comments