Skip to main content
deleted 107 characters in body
Source Link
gene
  • 55.4k
  • 3
  • 113
  • 191

Or another simple solution with numpy ravel():

import rasterio as rio
src= rio.open('myraster.tif')
# number of bands
src.count
3
# read bands
array1 = src.read(1)
array2 = src.read(2)
array3array = src.read(3)
# convert to a DataFrame
import pandas as pd
df = pd.DataFrame()
df['band1'] = array1array[0].ravel() 
df['band2'] = array2array[1].ravel() 
df['band3'] = array3array[2].ravel() 
df.head(2)
           band1 band2 band 3
0           250   249   254
1           250   249   254
2           250   249   254
3           250   249   254
4           250   249   254
df.tail(2) # last
           band1 band2 band 3
78608999    191   181   180
78609000    192   184   182
78609001    191   180   184
78609002    190   182   180
78609003    190   186   174

Or

Or another simple solution:

import rasterio as rio
src= rio.open('myraster.tif')
# number of bands
src.count
3
# read bands
array1 = src.read(1)
array2 = src.read(2)
array3 = src.read(3)
# convert to a DataFrame
import pandas as pd
df = pd.DataFrame()
df['band1'] = array1.ravel() 
df['band2'] = array2.ravel() 
df['band3'] = array3.ravel() 
df.head()
           band1 band2 band 3
0           250   249   254
1           250   249   254
2           250   249   254
3           250   249   254
4           250   249   254
df.tail() # last
           band1 band2 band 3
78608999    191   181   180
78609000    192   184   182
78609001    191   180   184
78609002    190   182   180
78609003    190   186   174

Or another simple solution with numpy ravel():

import rasterio as rio
src= rio.open('myraster.tif')
# number of bands
src.count
3
# read bands
array = src.read()
# convert to a DataFrame
import pandas as pd
df = pd.DataFrame()
df['band1'] = array[0].ravel() 
df['band2'] = array[1].ravel() 
df['band3'] = array[2].ravel() 
df.head(2)
           band1 band2 band 3
0           250   249   254
1           250   249   254
df.tail(2) # last
           band1 band2 band 3
78609002    190   182   180
78609003    190   186   174

Or

Source Link
gene
  • 55.4k
  • 3
  • 113
  • 191

Or another simple solution:

import rasterio as rio
src= rio.open('myraster.tif')
# number of bands
src.count
3
# read bands
array1 = src.read(1)
array2 = src.read(2)
array3 = src.read(3)
# convert to a DataFrame
import pandas as pd
df = pd.DataFrame()
df['band1'] = array1.ravel() 
df['band2'] = array2.ravel() 
df['band3'] = array3.ravel() 
df.head()
           band1 band2 band 3
0           250   249   254
1           250   249   254
2           250   249   254
3           250   249   254
4           250   249   254
df.tail() # last
           band1 band2 band 3
78608999    191   181   180
78609000    192   184   182
78609001    191   180   184
78609002    190   182   180
78609003    190   186   174