How to edit cells in a Pandas DataFrame without header?How do I check whether a file exists without exceptions?How to sort a dataframe by multiple column(s)Add one row to pandas DataFrameSelecting multiple columns in a pandas dataframeAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrameHow do I get the row count of a pandas DataFrame?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headers
Multi tool use
Having decision making power over someone's assets
Received a dinner invitation through my employer's email, is it ok to attend?
Given a 32 bit number, what is an efficient way to scale each byte by a certain factor?
Are there any sports for which the world's best player is female?
Is a request to book a business flight ticket for a graduate student an unreasonable one?
GDPR rights when subject dies; does family inherit subject rights?
How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?
Why does the Antonov AN-225 not have any winglets?
LED glows slightly during soldering
Postgres trigram match acting strange for specific characters
Why do we need common sense in AI?
Reverse dots and boxes
What is a "Lear Processor" and how did it work?
How can a dictatorship government be beneficial to a dictator in a post-scarcity society?
Do you need Read access to an object to view its records in a report?
What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?
How do we handle pauses in a dialogue?
How often does the spell Sleet Storm require concentration checks?
Elf (adjective) vs. Elvish vs. Elven
Would it be appropriate to sand a floor between coats of poly with a handheld orbital sander?
Can I play a mimic PC?
What happens when adult Billy Batson says "Shazam"?
A horrible Stockfish chess engine evaluation
Is there any reason why MCU changed the Snap to Blip
How to edit cells in a Pandas DataFrame without header?
How do I check whether a file exists without exceptions?How to sort a dataframe by multiple column(s)Add one row to pandas DataFrameSelecting multiple columns in a pandas dataframeAdding new column to existing DataFrame in Python pandasDelete column from pandas DataFrameHow do I get the row count of a pandas DataFrame?How to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headers
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a Pandas DataFrame without header and I need to edit all cells.
Cells are composed by a product name and a certain number, for example:
'Pasta=3'
Example:
0 1 2 3
0 'Pasta=3' 'Soup=2' 'Potatoes=4' None
1 'Cheese=1' 'Milk=2' None None
2 'Eggs=6' 'Cleaners=1' 'Beef=2' 'Fish=1'
3 'Apples=3' 'Banana=2' 'Pear=4' None
Now I have to remove the equality symbol and the number. So, if I have
'Pasta=3'
I have to remove '=3' to obtain
'Pasta'
How can I do it, if the dataframe hasn't header?
Thank you.
python python-3.x pandas dataframe
add a comment |
I have a Pandas DataFrame without header and I need to edit all cells.
Cells are composed by a product name and a certain number, for example:
'Pasta=3'
Example:
0 1 2 3
0 'Pasta=3' 'Soup=2' 'Potatoes=4' None
1 'Cheese=1' 'Milk=2' None None
2 'Eggs=6' 'Cleaners=1' 'Beef=2' 'Fish=1'
3 'Apples=3' 'Banana=2' 'Pear=4' None
Now I have to remove the equality symbol and the number. So, if I have
'Pasta=3'
I have to remove '=3' to obtain
'Pasta'
How can I do it, if the dataframe hasn't header?
Thank you.
python python-3.x pandas dataframe
add a comment |
I have a Pandas DataFrame without header and I need to edit all cells.
Cells are composed by a product name and a certain number, for example:
'Pasta=3'
Example:
0 1 2 3
0 'Pasta=3' 'Soup=2' 'Potatoes=4' None
1 'Cheese=1' 'Milk=2' None None
2 'Eggs=6' 'Cleaners=1' 'Beef=2' 'Fish=1'
3 'Apples=3' 'Banana=2' 'Pear=4' None
Now I have to remove the equality symbol and the number. So, if I have
'Pasta=3'
I have to remove '=3' to obtain
'Pasta'
How can I do it, if the dataframe hasn't header?
Thank you.
python python-3.x pandas dataframe
I have a Pandas DataFrame without header and I need to edit all cells.
Cells are composed by a product name and a certain number, for example:
'Pasta=3'
Example:
0 1 2 3
0 'Pasta=3' 'Soup=2' 'Potatoes=4' None
1 'Cheese=1' 'Milk=2' None None
2 'Eggs=6' 'Cleaners=1' 'Beef=2' 'Fish=1'
3 'Apples=3' 'Banana=2' 'Pear=4' None
Now I have to remove the equality symbol and the number. So, if I have
'Pasta=3'
I have to remove '=3' to obtain
'Pasta'
How can I do it, if the dataframe hasn't header?
Thank you.
python python-3.x pandas dataframe
python python-3.x pandas dataframe
edited Mar 26 at 1:08
hrakkar
asked Mar 26 at 0:52
hrakkarhrakkar
32 bronze badges
32 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First of all, they have a "header" (i.e. column name). In your case, it is either 0
or "0"
(integer 0, or string 0). So you can still access the columns by df[0]
or df["0"]
depending on whether that's a integer or string.
Second, to remove everything after the =
, just use df.replace
on every column by stating regex=True
df.replace(r'=.*','', regex=True)
You can also use apply
(slower, prefer the first method)
df.apply(lambda s: s.str.replace(r'=.*',''))
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348385%2fhow-to-edit-cells-in-a-pandas-dataframe-without-header%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, they have a "header" (i.e. column name). In your case, it is either 0
or "0"
(integer 0, or string 0). So you can still access the columns by df[0]
or df["0"]
depending on whether that's a integer or string.
Second, to remove everything after the =
, just use df.replace
on every column by stating regex=True
df.replace(r'=.*','', regex=True)
You can also use apply
(slower, prefer the first method)
df.apply(lambda s: s.str.replace(r'=.*',''))
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
add a comment |
First of all, they have a "header" (i.e. column name). In your case, it is either 0
or "0"
(integer 0, or string 0). So you can still access the columns by df[0]
or df["0"]
depending on whether that's a integer or string.
Second, to remove everything after the =
, just use df.replace
on every column by stating regex=True
df.replace(r'=.*','', regex=True)
You can also use apply
(slower, prefer the first method)
df.apply(lambda s: s.str.replace(r'=.*',''))
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
add a comment |
First of all, they have a "header" (i.e. column name). In your case, it is either 0
or "0"
(integer 0, or string 0). So you can still access the columns by df[0]
or df["0"]
depending on whether that's a integer or string.
Second, to remove everything after the =
, just use df.replace
on every column by stating regex=True
df.replace(r'=.*','', regex=True)
You can also use apply
(slower, prefer the first method)
df.apply(lambda s: s.str.replace(r'=.*',''))
First of all, they have a "header" (i.e. column name). In your case, it is either 0
or "0"
(integer 0, or string 0). So you can still access the columns by df[0]
or df["0"]
depending on whether that's a integer or string.
Second, to remove everything after the =
, just use df.replace
on every column by stating regex=True
df.replace(r'=.*','', regex=True)
You can also use apply
(slower, prefer the first method)
df.apply(lambda s: s.str.replace(r'=.*',''))
answered Mar 26 at 1:17
rafaelcrafaelc
31.2k8 gold badges32 silver badges55 bronze badges
31.2k8 gold badges32 silver badges55 bronze badges
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
add a comment |
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
It worked very well! Thank you so much :)
– hrakkar
Mar 26 at 10:33
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348385%2fhow-to-edit-cells-in-a-pandas-dataframe-without-header%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
riY3s00 h878tBYZn4mG6p1oeYI l6fShj s6ub NaZbxJgSfY,peJTsaVaC0JB7XO9X S3,Dg,3bSf