When you say the column has disappeared from the attribute table in the shapefile, I am going to assume you mean it's disappeared from the column drop-down list when you paste the symbology (presumably Categorised symbology) from the CSV to the shapefile.
And now the symbology isn't working properly any more because QGIS (and you) can't find the column that was used to categorise the symbology.
This can happen when your CSV column names are more than 10 characters long (including spaces etc), as shapefiles cannot support column names more than 10 characters long. So when converting CSV to shapefile, these column names get truncated by QGIS. For example,
"Tree_health_2018" in your CSV gets truncated to
"Tree_healt" in your shapeflie.
Furthermore, if you have many columns in your CSV that have the same first 10 letters, the truncation will replace the 10th letter with a number in QGIS. e.g.
"Tree_health_2020" in your CSV would get truncated to
"Tree_heal2" respectively (or something similar).
This also applies when you are doing a join - let's say my shapefile has the above three columns, and now I want to join a column from the CSV called
"Tree_health_2021". This will get truncated to
"Tree_heal3" or similar.
See examples in Export shapefile with column name of csv file or change column names afterwards and When I join a table to a shapefile and then export it the titles of the columns are transformed to data1, data2
For your symbology to work properly when copied and pasted from one layer to another, it needs to have the same exact column names used to categorise or otherwise define the symbology (e.g. rule-based symbology, data-defined overrides for colour or size, etc.).
Some solutions for this specific problem:
- Change your symbology on the shapefile layer to use the truncated column name, instead of the original column name. If it is just a categorised symbology, you can use the column drop down box to find the right column. If it's a rule-based or otherwise complex symbology, you will need to find every reference to that column name and update accordingly.
Note: Once you have done this, you can save the symbology as a
.qml file and/or save it as the default styling so it doesn't need to be re-created each time.
- Make sure you do not have column names that have the same 10 first characters (especially when you apply the join from the CSV to the shapefile).
- Make sure your CSV only uses shapefile appropriate column names from the start (10 standard characters max including spaces).
- Don't use shapefile, use another spatial format such as geopackage that doesn't have this archaic 10-character limit.