Manually set the keys in Pandas DataFrame built with read_csv

albero123

I have a .tsv file dataset, and I transformed it into a DataFrame using Pandas. Imagine that my_tsv_file was something like:

A Apple
B Orange
C Pear

To build the DataFrame I used:

df = pandas.read_csv(my_tsv_file, sep='\t')

Now, the first row of my_tsv_file was originally a row part of the data, but it has been transformed to the "key row" in the new DataFrame. So now the Dataframe is something like:

      A Apple
   0  B Orange
   1  C Pear

As "A" and "Apple" were keys, when they actually are not. I would like to add the correct "key row", in order to obtain something like:

      ID Fruit
   0  A  Apple
   1  B  Orange
   2  C  Pear

How can I achieve this? I can't modify the original .tsv file. Please remind that I am at the very beginning with Python and Pandas.

Kenan

have you tried

df = pandas.read_csv(my_tsv_file, sep='\t', names=['ID', 'Fruit'])

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Calculate STD manually using Groupby Pandas DataFrame

分類Dev

C# Pandas read_csv Equivalent

分類Dev

Pandas read_csv only first comma

分類Dev

Dictionary to CSV with Pandas to_csv and reload it with read_csv

分類Dev

How to read large data set from mongodb to pandas dataframe

分類Dev

Python pandas: convert dictionary to DataFrame with keys as row

分類Dev

Radio buttons built with ngFor work. Identical set build manually don't Angular 2+

分類Dev

Pandas read_csv not recognizing ISO8601 as datetime dtype

分類Dev

Pandas read_csv reads rows wrongfully as dictionaries

分類Dev

Pandas, importing JSON-like file using read_csv

分類Dev

Python : Pandas DataFrame to CSV

分類Dev

Python Pandas read_csv():誤って読み込まれたcsv

分類Dev

Serving manually set time

分類Dev

Manually Set UINavigationController Children

分類Dev

パンダread_csvを複数のDataFrameに

分類Dev

pandas read text file into a dataframe

分類Dev

Pandas read_csv converter – How to handle exceptions (literal_eval SyntaxError)

分類Dev

Python Pandas DataFrame(read_csv()メソッド)に、csv / txtファイルの最初の行をヘッダーとして回避/考慮しないように強制します

分類Dev

Manually create dataframe with date column

分類Dev

Manually Set Value for FormBuilder Control

分類Dev

R manually set shape by factor

分類Dev

Python Pandas return DataFrame where value count is above a set number

分類Dev

How to set the index of a pandas DataFrame to match the index of a datetime series?

分類Dev

'DataFrame'オブジェクトには属性 'read_csv'がありません

分類Dev

Python Pandas - Quantile calculation manually

分類Dev

モジュール 'pandas'には属性 'read_csvがありません

分類Dev

Python Pandas read_csvで複数の文字区切り文字を使用する

分類Dev

AttributeError:モジュール 'pandas'には属性 'read_csv'がありません

分類Dev

pandas read_csv()とpythonイテレータを入力として

Related 関連記事

  1. 1

    Calculate STD manually using Groupby Pandas DataFrame

  2. 2

    C# Pandas read_csv Equivalent

  3. 3

    Pandas read_csv only first comma

  4. 4

    Dictionary to CSV with Pandas to_csv and reload it with read_csv

  5. 5

    How to read large data set from mongodb to pandas dataframe

  6. 6

    Python pandas: convert dictionary to DataFrame with keys as row

  7. 7

    Radio buttons built with ngFor work. Identical set build manually don't Angular 2+

  8. 8

    Pandas read_csv not recognizing ISO8601 as datetime dtype

  9. 9

    Pandas read_csv reads rows wrongfully as dictionaries

  10. 10

    Pandas, importing JSON-like file using read_csv

  11. 11

    Python : Pandas DataFrame to CSV

  12. 12

    Python Pandas read_csv():誤って読み込まれたcsv

  13. 13

    Serving manually set time

  14. 14

    Manually Set UINavigationController Children

  15. 15

    パンダread_csvを複数のDataFrameに

  16. 16

    pandas read text file into a dataframe

  17. 17

    Pandas read_csv converter – How to handle exceptions (literal_eval SyntaxError)

  18. 18

    Python Pandas DataFrame(read_csv()メソッド)に、csv / txtファイルの最初の行をヘッダーとして回避/考慮しないように強制します

  19. 19

    Manually create dataframe with date column

  20. 20

    Manually Set Value for FormBuilder Control

  21. 21

    R manually set shape by factor

  22. 22

    Python Pandas return DataFrame where value count is above a set number

  23. 23

    How to set the index of a pandas DataFrame to match the index of a datetime series?

  24. 24

    'DataFrame'オブジェクトには属性 'read_csv'がありません

  25. 25

    Python Pandas - Quantile calculation manually

  26. 26

    モジュール 'pandas'には属性 'read_csvがありません

  27. 27

    Python Pandas read_csvで複数の文字区切り文字を使用する

  28. 28

    AttributeError:モジュール 'pandas'には属性 'read_csv'がありません

  29. 29

    pandas read_csv()とpythonイテレータを入力として

ホットタグ

アーカイブ