Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show my existing column name instead '_c0', '_c1', '_c2', '_c3', '_c4' in first row?

Data frame showing _c0,_c1 instead my original column names in first row.
i want to show My column name which is on first row of my CSV.

    dff = 
    spark.read.csv("abfss://[email protected]/
    diabetes.csv")
    dff:pyspark.sql.dataframe.DataFrame
    _c0:string
    _c1:string
    _c2:string
    _c3:string
    _c4:string
    _c5:string
    _c6:string
    _c7:string
    _c8:string
like image 894
Gaurav Gangwar Avatar asked Aug 01 '19 12:08

Gaurav Gangwar


People also ask

How to change column name in list in R?

Method 1: using colnames() method colnames() method in R is used to rename and replace the column names of the data frame in R. The columns of the data frame can be renamed by specifying the new column names as a vector.

How do I change the type of column spark?

To change the Spark SQL DataFrame column type from one data type to another data type you should use cast() function of Column class, you can use this on withColumn(), select(), selectExpr(), and SQL expression.

How do I modify columns in PySpark?

You can do update a PySpark DataFrame Column using withColum(), select() and sql(), since DataFrame's are distributed immutable collection you can't really change the column values however when you change the value using withColumn() or any approach, PySpark returns a new Dataframe with updated values.

Which of the following will be check if column name have been included in the first row of the file?

When importing, there is a checkbox for "The first line of the file contains the table column names (if this is unchecked, the first line will become part of the data)". Checking that box will use the first row as the column names, saving you from having to write any additional script or manually change anything.

How to change the name of a R1C1 column in Excel?

You can change the names of the columns to reflect R1C1 cell addressing, but you cannot rename column A " House ". A work-around that you may find acceptable would be to use row 1 for your column heading labels, and then remove the column and row labels from view.

Where do I find the R1C1 reference style in Excel?

Click the Office button, then the Excel Options button in the lower right. Select Formulas within the list at the left and scroll down to Working with Formulas (second group of options). The R1C1 reference style option should be the first in this group.

How are column names and descriptions determined before fetching data?

You can see that when you use the DBMS_SQL package, where the query has to be parsed and the column names and descriptions are determined before any fetching of data. This discussion has been closed.

Is it possible to refer to a column in a table?

Is it possible to refer to a column in a table with something like Columns ("Name").Value instead of Cells (n,m)? Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar). You can use the ListColumns property to get a column.


2 Answers

Very simple solution is to have a header=True while you read the file:

dff = spark.read.csv("abfss://[email protected]/diabetes.csv", header=True)
like image 108
Kishan Vyas Avatar answered Dec 28 '22 13:12

Kishan Vyas


Set header as true while loading the CSV file.

spark.read.format("csv")
                   .option("delimiter", ",")
                   .option("header", "true")
                   .option("inferSchema", "true")
                   .load("file.csv")
like image 36
Aman Sehgal Avatar answered Dec 28 '22 14:12

Aman Sehgal