UnboundLocalError: local variable 'data' referenced before assignment
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 20/100
Línea de trabajo
Comienza con el código del issue, especialmente con outer_function y el bucle que lee Sheet1. Ejecuta el ejemplo para reproducir el UnboundLocalError y, a continuación, sigue las rutas en las que se asignan y consumen los datos; se considera completado cuando el ejemplo maneja el contenido relevante de la hoja de cálculo sin hacer referencia a una variable local no establecida.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
import xlsxwriter
import pandas as pd
import openpyxl
import pandas as pd
current=1
i = 0
counter=0
Create some Pandas dataframes from some data.
df1 = pd.DataFrame({'Data1': [11, 12, 13, 14]})
df2 = pd.DataFrame({'Data2': [21, 22, 23, 24,25]})
df3 = pd.DataFrame({'Data3': [31, 32, 33, 34,35,36]})
df4 = pd.DataFrame({'Data4': [41, 42, 43, 44,45,46,47]})
df5 = pd.DataFrame({'Data5': [51, 52, 53, 54,55,56,57,58]})
Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_positioning.xlsx', engine='xlsxwriter')
Position the dataframes in the worksheet.
df1.to_excel(writer, sheet_name='Sheet1',startrow=0) # Default position, cell A1.
df2.to_excel(writer, sheet_name='Sheet1', startcol=0,startrow=5)
df3.to_excel(writer, sheet_name='Sheet1', startrow=0,startcol=11)
df3.to_excel(writer, sheet_name='Sheet1', startrow=0,startcol=18)
df3.to_excel(writer, sheet_name='Sheet1', startrow=0,startcol=26)
It is also possible to write the dataframe without the header and index.
#df4.to_excel(writer, sheet_name='Sheet1', startrow=7, startcol=4, header=False, index=False)
Close the Pandas Excel writer and output the Excel file.
writer.save()
def outer_function():
import xlrd
wb=xlrd.open_workbook('C:/Users/bened/pandas_positioning.xlsx')
sheet=wb.sheet_by_name('Sheet1')
for i in range(sheet.nrows):
if(sheet.cell_value(i,0)=='Data3'):
data=i
d=0
while(d<data):
print('hi')
break
outer_function()
how do i solve UnboundLocalError: local variable 'data' referenced before assignment
- Lenguaje dominante
- Python
- Estrellas
- 35.4k
- Forks
- 12.9k
- Merge medio
- 2 h 37 min
- PR fusionados (30 d)
- 1
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de geekcomputers/Python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
geekcomputers/Python#3205 · 2 comentarios ·
-
Add number_guesse.py feature Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
geekcomputers/Python#3188 · 3 comentarios ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
geekcomputers/Python#3060 · 1 comentario ·
-
[BUG] shapchat Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
geekcomputers/Python#3214 · 5 comentarios ·
-
Test of an Issue Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
geekcomputers/Python#3209 · 5 comentarios ·
Todos los issues de geekcomputers/Python
Issues similares
-
link-check link-check:sphinx-theme
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenHands/extensions#626 · 1 comentario ·
-
Change observation tooltip text Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
CSCfi/sd-search-api#39 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100